async_hooks: only disable promise hook if wanted by addaleax · Pull Request #27590 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/internal/async_hooks.js
13 changes: 4 additions & 9 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,10 @@ static void EnablePromiseHook(const FunctionCallbackInfo<Value>& args) {
static void DisablePromiseHook(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();

// Delay the call to `RemovePromiseHook` because we might currently be
// between the `before` and `after` calls of a Promise.
isolate->EnqueueMicrotask([](void* data) {
// The per-Isolate API provides no way of knowing whether there are multiple
// users of the PromiseHook. That hopefully goes away when V8 introduces
// a per-context API.
Isolate* isolate = static_cast<Isolate*>(data);
isolate->SetPromiseHook(nullptr);
}, static_cast<void*>(isolate));
// The per-Isolate API provides no way of knowing whether there are multiple
// users of the PromiseHook. That hopefully goes away when V8 introduces
// a per-context API.
isolate->SetPromiseHook(nullptr);
}


Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-async-hooks-enable-disable-enable.js