Skip to content

N-API feature request: expose API to resolve promises asynchronously without napi_create_async_work #15604

Description

@rolftimmermans

My use case: I have a socket that I'm polling with libuv uv_poll_t. When an event is present I want to resolve a promise.

Calling napi_resolve_deferred() does not work for me because it does not appear to run microtasks.

Looking at the test added in this commit I need to use the following code before resolving the promise.

v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
node::CallbackScope callback_scope(isolate, v8::Object::New(isolate), {0, 0});

// resolve promise here

This works perfectly; but now I am required to pull in both v8.h and node.h. It would be nice if there were N-API method to resolve promises with napi_resolve_deferred() asynchronously.

Note that I am not able to use napi_create_async_work()/napi_queue_async_work() for the async code in this case.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.node-apiIssues and PRs related to Node-API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions