Skip to content

Instantly share code, notes, and snippets.

@tonylukasavage
Created September 1, 2017 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonylukasavage/a6d0c0c4258a52dbded1fd0131401207 to your computer and use it in GitHub Desktop.
Save tonylukasavage/a6d0c0c4258a52dbded1fd0131401207 to your computer and use it in GitHub Desktop.
basic async_hooks test
const async_hooks = require('async_hooks'),
fs = require('fs'),
http = require('http');
const hook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId, resource) {
fs.writeSync(1, `[init] (${asyncId}:${triggerAsyncId}) ${type} - ${resource}\n`);
},
before(asyncId) {
fs.writeSync(1, `[before] (${asyncId})\n`);
},
after(asyncId) {
fs.writeSync(1, `[after] (${asyncId})\n`);
},
destroy(asyncId) {
fs.writeSync(1, `[destroy] (${asyncId})\n`);
}
}).enable();
http.createServer((req, res) => res.end()).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment