2021-02-08 00:33:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const initHooks = require('./init-hooks');
|
|
|
|
const async_hooks = require('async_hooks');
|
|
|
|
|
|
|
|
if (!common.isMainThread)
|
|
|
|
common.skip('Worker bootstrapping works differently -> different async IDs');
|
|
|
|
|
|
|
|
const promiseAsyncIds = [];
|
|
|
|
const hooks = initHooks({
|
|
|
|
oninit(asyncId, type) {
|
|
|
|
if (type === 'PROMISE') {
|
|
|
|
promiseAsyncIds.push(asyncId);
|
|
|
|
}
|
2022-11-22 01:43:47 +08:00
|
|
|
},
|
2021-02-08 00:33:33 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
hooks.enable();
|
|
|
|
Promise.reject();
|
|
|
|
|
|
|
|
process.on('unhandledRejection', common.mustCall(() => {
|
|
|
|
assert.strictEqual(promiseAsyncIds.length, 1);
|
|
|
|
assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[0]);
|
|
|
|
}));
|