mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 20:39:30 +00:00

This avoids the need to wrap every promise in an AsyncWrap and also makes it easier to skip the machinery to track destroy events when there's no destroy listener. Co-authored-by: Andrey Pechkurov <apechkurov@gmail.com> PR-URL: https://github.com/nodejs/node/pull/32891 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
28 lines
793 B
JavaScript
28 lines
793 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const async_hooks = require('async_hooks');
|
|
|
|
if (!common.isMainThread)
|
|
common.skip('Worker bootstrapping works differently -> different async IDs');
|
|
|
|
const initCalls = [];
|
|
const resolveCalls = [];
|
|
|
|
async_hooks.createHook({
|
|
init: common.mustCall((id, type, triggerId, resource) => {
|
|
assert.strictEqual(type, 'PROMISE');
|
|
initCalls.push({ id, triggerId, resource });
|
|
}, 2),
|
|
promiseResolve: common.mustCall((id) => {
|
|
assert.strictEqual(initCalls[resolveCalls.length].id, id);
|
|
resolveCalls.push(id);
|
|
}, 2)
|
|
}).enable();
|
|
|
|
const a = Promise.resolve(42);
|
|
a.then(common.mustCall());
|
|
|
|
assert.strictEqual(initCalls[0].triggerId, 1);
|
|
assert.strictEqual(initCalls[1].triggerId, initCalls[0].id);
|