Basically like the title says, is there a way to see how many promises currently exist within the event loop from within the JavaScript program? Preferably on Deno.
Deno v1.26 added an internal API that can be used to track promises.
Deno.core.setPromiseHooks(init, before, after, resolve);
Deno.core.setPromiseHooks(
// init
(promise, parentPromise) => {
console.log('init', promise, parentPromise);
},
// before
promise => {},
// after
promise => {},
// resolve
promise => {
console.log(promise, 'resolved');
}
);
For a detailed usage check the following Deno test:
https://github.com/denoland/deno/blob/main/cli/tests/unit/promise_hooks_test.ts
NOTE: The API is undocumented and may change in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With