Closed
Description
Promise.all
to observe input promises, invokes promise.then
in next event loop, at least it's what stack traces show in both Node.js and Google Chrome.
Still Async Hooks see it as same execution context, it can be seen by running following code:
const async_hooks = require('async_hooks');
async_hooks.createHook({ init() {} }).enable();
Promise.all([
{
then() {
console.log(async_hooks.executionAsyncId(), async_hooks.triggerAsyncId(), 'thenable.then invoked by Promise.all');
console.trace('thenable.then invoked by Promise.all');
},
},
]);
console.log(async_hooks.executionAsyncId(), async_hooks.triggerAsyncId(), 'Main');
console.trace('Main');
The outcome is:
1 0 'Main'
Trace: Main
at Object.<anonymous> (/Users/medikoo/Projects/maas/maas-backend/test.js:15:9)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:266:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
1 0 'promise.then invoked by Promise.all'
Trace: promise.then invoked by Promise.all
at Object.then (/Users/medikoo/Projects/maas/maas-backend/test.js:9:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:266:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
I've stumbled on that when trying to configure long stack trace solution for Node.js, and was dealing with custom promise implementations.
I believe that's not expected.
- Version: v10.9.0 (observable also on v8)
- Platform: macOs 10.13.6 (17G65)