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');
console.log('+');
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");
});
});
function create(name) {
assert.ok(name, "namespace must be given a name!");
var namespace = new Namespace(name);
namespace.id = process.addAsyncListener(
function () {
process._rawDebug(util.inspect(namespace.id));
process._rawDebug(new Error('listener called').stack);
return namespace.active;
},
{
before : function (context, domain) { namespace.enter(domain); },
after : function (context, domain) { namespace.exit(domain); }
}
);
namespaces[name] = namespace;
return namespace;
}
@othiym23

This comment has been minimized.

Copy link
Owner Author

commented Sep 29, 2013

Here's what this produces. I'm pretty sure the middle call shouldn't be happening on this same function calling chain.

% PATH=$NUPATH node mnmzd.tap.js
+
{ callbacks: { before: [Function], after: [Function] },
  domain: undefined,
  listener: [Function] }
Error: listener called
    at Object.listener (/Users/forrest/Documents/projects/newrelic/nodejs-agent-git/node_modules/continuation-local-storage/context.js:97:25)
    at runAsyncQueue (node.js:314:23)
    at exports.setImmediate (timers.js:396:5)
    at global.setImmediate (node.js:200:29)
    at /Users/forrest/Documents/projects/newrelic/nodejs-agent-git/mnmzd.tap.js:14:3
    at Namespace.run (/Users/forrest/Documents/projects/newrelic/nodejs-agent-git/node_modules/continuation-local-storage/context.js:35:5)
    at Object.<anonymous> (/Users/forrest/Documents/projects/newrelic/nodejs-agent-git/mnmzd.tap.js:10:3)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
{ callbacks: { before: [Function], after: [Function] },
  domain: { state: true },
  listener: [Function] }
Error: listener called
    at Object.listener (/Users/forrest/Documents/projects/newrelic/nodejs-agent-git/node_modules/continuation-local-storage/context.js:97:25)
    at Object.runAsyncQueue (node.js:314:23)
    at createWriteReq (net.js:707:21)
    at WriteStream.Socket._writeGeneric (net.js:650:11)
    at WriteStream.Socket._write (net.js:673:8)
    at doWrite (_stream_writable.js:257:12)
    at writeOrBuffer (_stream_writable.js:244:5)
    at WriteStream.Writable.write (_stream_writable.js:191:11)
    at WriteStream.Socket.write (net.js:600:40)
    at Console.log (console.js:53:16)
!
{ callbacks: { before: [Function], after: [Function] },
  domain: {},
  listener: [Function] }
Error: listener called
    at Object.listener (/Users/forrest/Documents/projects/newrelic/nodejs-agent-git/node_modules/continuation-local-storage/context.js:97:25)
    at runAsyncQueue (node.js:314:23)
    at process.nextTick (node.js:569:9)
    at onwrite (_stream_writable.js:303:15)
    at WritableState.onwrite (_stream_writable.js:100:5)
    at WriteStream.Socket._writeGeneric (net.js:661:5)
    at WriteStream.Socket._write (net.js:673:8)
    at doWrite (_stream_writable.js:257:12)
    at writeOrBuffer (_stream_writable.js:244:5)
    at WriteStream.Writable.write (_stream_writable.js:191:11)

assert.js:92
  throw new assert.AssertionError({
        ^
AssertionError: state should be visible
    at Object._onImmediate (/Users/forrest/Documents/projects/newrelic/nodejs-agent-git/mnmzd.tap.js:15:12)
    at processImmediate [as _immediateCallback] (timers.js:358:15)
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.