Skip to content

add AsyncResource::makeCallbackScope - #1026

Open
mmomtchev wants to merge 1 commit into
nodejs:mainfrom
mmomtchev:makeCallbackScope
Open

mmomtchev wants to merge 1 commit into
nodejs:mainfrom
mmomtchev:makeCallbackScope

Conversation

@mmomtchev

Copy link
Copy Markdown
Contributor

Refs: #1024

Add nan::AsyncResource::makeCallbackScope wrapper aroiund node::CallbackScope.

The problem with calling node::CallbackScope directly is that the node::async_context is a private member of nan::AsyncResource.

This allows to run properly the microtasks queue for async workers that do not call JavaScript.

This require Node.js 9.0.0, as before this version the microtasks queue was always run automatically.

In reality, Node.js 26.4.0 is the first version that actually does not do this, although this has been specified since Node.js 9.0.0.

@mmomtchev mmomtchev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a non-copyable object from a factory using an initializer-list is C++11.

Comment thread nan.h
inline node::CallbackScope makeCallbackScope(v8::Local<v8::Object> target) {
return {v8::Isolate::GetCurrent(), target, context};
}
#endif

@Flarna Flarna Sep 25, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this require an ifdef for all users supporting ancient node.js versions if there is no dummy implementation for these older node.js versions?

@kkoopa

kkoopa commented Sep 25, 2026 via email

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants