Hi @denyhs, I tried but I have another problem. It seems that nested calls are not handled correctly, below is a simple example:
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
const linkContext1 = new Meteor.EnvironmentVariable();
const linkContext2 = new Meteor.EnvironmentVariable();
linkContext1.withValue({ idd: Random.id() }, async () => {
await linkContext2.withValue({ idd: Random.id() }, async () => {
await linkContext2.withValue({ idd: Random.id() }, async () => {
console.log(' Link context 2', linkContext2.get())
})
console.log(' Link context 2', linkContext2.get())
})
console.log('Link context 1', linkContext1.get())
console.log('Link context 2', linkContext2.get())
});
The result is:
Link context 2 { idd: 'nai9jtXk7mAdrQq5N' }
Link context 2 { idd: 'Di6aKku65s2pdne5L' }
Link context 1 { idd: 'E97X6ZwjM6cEjbxpN' }
**Link context 2 { idd: 'Di6aKku65s2pdne5L' } // Should be undefined but we have the last id**
As a curiosity, do you see any contraindications in using AsyncLocalStorage directly for some properties without going through Meteor.EnvironmentVariable?