Logo
Explore Help
Sign In
1berry/nodejs
1
0
Fork 0
You've already forked nodejs
Code Issues Packages Projects Releases Wiki Activity
nodejs/test/parallel/test-async-hooks-enable-during-promise.js

14 lines
321 B
JavaScript
Raw Normal View History

async_hooks: proper id stacking for Promises Until now, the async_hooks PromiseHook did not register the Promise’s async id and trigger id on the id stack, so inside the `.then()` handler those ids would be invalid. To fix this, add push and pop calls to its `before` and `after` parts, respectively. Some care needs to be taken for the cases that the Promise hook is being disabled or enabled during the execution of a Promise handler; in the former case, actually removing the hook is delayed by adding another task to the microtask queue, in the latter case popping the id off the async id stack is skipped if the ids don’t match. Fixes: https://github.com/nodejs/node/issues/13583 PR-URL: https://github.com/nodejs/node/pull/13585 Reviewed-By: Trevor Norris <trevnorris@gmail.com>
2017-06-09 21:27:02 +02:00
'use strict';
const common = require('../common');
const async_hooks = require('async_hooks');
Promise.resolve(1).then(common.mustCall(() => {
async_hooks.createHook({
init: common.mustCall(),
before: common.mustCall(),
after: common.mustCall(2)
}).enable();
process.nextTick(common.mustCall());
}));
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.8 Page: 424ms Template: 2ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API