Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var assert = require('assert');
var cls = require('continuation-local-storage');
setImmediate(function () { console.log('!'); });
var n = cls.createNamespace("test2");
assert.ok(!n.get('state'), "state should not yet be visible");
n.run(function () {
n.set('state', true);
assert.ok(n.get('state'), "state should be visible");
setImmediate(function () { assert.ok(n.get('state'), "state should be visible"); });
});
@othiym23

This comment has been minimized.

Copy link
Owner Author

commented Sep 29, 2013

Stepping through the execution of this test in the debugger, I was able to see an asyncQueue created with an async object that has a domain of {state : true}, and then later, after the console.log, when it's time to be run, the domain has changed value to {}!

When console.log runs, it's getting hit for the first time and goes to compile. When the compilation hits the instantiation of ContextifyScript, that triggers runAsyncQueue and in turn the async queue object's listener, which causes the domain for the existing async object to be overwritten, out of scope of the intended domain. I'll look at what's going on in contextify to see if I can figure out why that's causing runAsyncQueue to fire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.