Skip to content

await breaks context #143

@mikhailrojo

Description

@mikhailrojo

Hi guys

I used your library as a dependency of zipkin package.
And I spent 2 days and realized this context doesn't work with await at all

var createNamespace = require('continuation-local-storage').createNamespace;
var session = createNamespace('my session');

const fn = async () => {
	console.log('before await => ', session.get('misha')); // before await =>  yo man
	await Promise.resolve(1);
	console.log('after await => ', session.get('misha')); // after await =>  undefined
};

(async () => {
	session.run(async() => {
		session.set('misha', 'yo man');
		fn();
	});
})();

So if in my code there are awaits, and in enterprize there are a lot of awaits... then context will be lost just right after await.

v10.16.3 test in

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions