Skip to content

Instantly share code, notes, and snippets.

@guyguyon
Created November 23, 2017 16:41
Show Gist options
  • Select an option

  • Save guyguyon/3340a1ac45732c75eb6d19a528ec7d2c to your computer and use it in GitHub Desktop.

Select an option

Save guyguyon/3340a1ac45732c75eb6d19a528ec7d2c to your computer and use it in GitHub Desktop.
const fs = require('fs');
const async_hooks = require('async_hooks');
async_hooks.createHook({
init(asyncId, type, triggerAsyncId) {
fs.writeSync(1, `Init ${type} resource: asyncId: ${asyncId} trigger: ${triggerAsyncId}\n`);
},
destroy(asyncId) {
const eid = async_hooks.executionAsyncId();
fs.writeSync(1, `Destroy resource: execution: ${eid} asyncId: ${asyncId}\n`);
}
}).enable();
const eid = async_hooks.executionAsyncId();
fs.writeSync(1, `Calling setTimeout: execution: ${eid}\n`);
setTimeout(() => {
const eid = async_hooks.executionAsyncId();
fs.writeSync(1, `Inside setTimeout: execution: ${eid}\n`);
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment