Created
August 30, 2018 20:43
-
-
Save mafintosh/0d3008428d830d6ce833910d4d1a5e1d 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 hooks = require('async_hooks') | |
const promises = new Set() | |
const hook = hooks.createHook({ | |
init (asyncId, type) { | |
if (type === 'PROMISE') { | |
promises.add(asyncId) | |
} | |
}, | |
after (asyncId) { | |
promises.delete(asyncId) | |
}, | |
destroy (asyncId) { | |
promises.delete(asyncId) | |
} | |
}) | |
hook.enable() | |
function wait () { | |
return new Promise(function (resolve) { | |
setTimeout(resolve, 100) | |
}) | |
} | |
async function foo () { | |
await wait() | |
await wait() | |
} | |
foo() | |
setTimeout(function () { | |
hook.disable() | |
console.log('promises.size', promises.size) | |
}, 500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment