Created
February 17, 2021 04:35
-
-
Save bmax/977433a31e1a9a067b44fd6d9ef432ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const async_hooks = require('async_hooks') | |
const fs = require('fs') | |
// Create a new AsyncHook instance. All of these callbacks are optional. | |
const asyncHook = async_hooks.createHook({ | |
init, | |
before, | |
after, | |
destroy, | |
promiseResolve, | |
}) | |
asyncHook.enable() | |
setTimeout(() => { | |
console.log('test1') | |
}, 1000) | |
asyncHook.disable() | |
function init(asyncId, type, triggerAsyncId, resource) { | |
const eid = async_hooks.executionAsyncId() | |
fs.writeSync( | |
1, | |
`${type}(${asyncId}): trigger: ${triggerAsyncId} execution: ${eid}\n` | |
) | |
} | |
function before(asyncId) { | |
fs.writeSync(1, `before ${asyncId}`) | |
} | |
function after(asyncId) { | |
fs.writeSync(1, `after ${asyncId}`) | |
} | |
function destroy(asyncId) { | |
fs.writeSync(1, `destroy ${asyncId}`) | |
} | |
function promiseResolve(asyncId) { | |
fs.writeSync(1, `promise ${asyncId}`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment