Skip to content

Instantly share code, notes, and snippets.

@rmg
Last active January 2, 2016 13:19
Show Gist options
  • Save rmg/8309662 to your computer and use it in GitHub Desktop.
Save rmg/8309662 to your computer and use it in GitHub Desktop.
Domain double-pop
var domain = require('domain')
, d1 = new domain.Domain()
, d2 = new domain.Domain()
, d3 = new domain.Domain()
, d4 = new domain.Domain()
console.log("Starting: ", domain._stack)
d1.enter()
console.log("Entered d1: ", domain._stack)
d2.enter()
console.log("Entered d2: ", domain._stack)
d3.enter()
console.log("Entered d3: ", domain._stack)
d2.exit()
console.log("Exitted d2: ", domain._stack)
d2.exit()
console.log("Exitted d2 again: ", domain._stack)
d1.enter()
d2.enter()
d3.enter()
console.log("Re-entered d1, d2, d3: ", domain._stack)
d4.exit()
console.log("Exitted unused d4: ", domain._stack)
Starting: []
Entered d1: [ { domain: null, _events: {}, _maxListeners: 10, members: [] } ]
Entered d2: [ { domain: null, _events: {}, _maxListeners: 10, members: [] },
{ domain: null, _events: {}, _maxListeners: 10, members: [] } ]
Entered d3: [ { domain: null, _events: {}, _maxListeners: 10, members: [] },
{ domain: null, _events: {}, _maxListeners: 10, members: [] },
{ domain: null, _events: {}, _maxListeners: 10, members: [] } ]
Exitted d2: [ { domain: null, _events: {}, _maxListeners: 10, members: [] } ]
Exitted d2 again: []
Re-entered d1, d2, d3: [ { domain: null, _events: {}, _maxListeners: 10, members: [] },
{ domain: null, _events: {}, _maxListeners: 10, members: [] },
{ domain: null, _events: {}, _maxListeners: 10, members: [] } ]
Exitted unused d4: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment