Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to synchronously drain a thread safe function #31531

Open
legendecas opened this issue Jan 27, 2020 · 2 comments
Open

Ability to synchronously drain a thread safe function #31531

legendecas opened this issue Jan 27, 2020 · 2 comments
Labels
node-api Issues and PRs related to the Node-API.

Comments

@legendecas
Copy link
Member

Is your feature request related to a problem? Please describe.
Since TSFN provides a queue to caching up calls to the creating thread, we don't have the ability to drain the queue if we think it's time to complete the job.

Describe the solution you'd like
Add a drain method to synchronously drain the threadsafe function (maybe mark it as closed too).

Describe alternatives you've considered
Release the tsfn with napi_release_threadsafe_function(tsfn, napi_tsfn_release) and wait the finalizer to be called asynchronously.

@legendecas legendecas added the node-api Issues and PRs related to the Node-API. label Jan 27, 2020
@gabrielschulhof
Copy link
Contributor

@legendecas TBH I'm not sure if we can provide a synchronous API for draining the queue. AFAICT we would have to basically hijack the event loop by creating second event loop that runs until the queue is drained.

@legendecas
Copy link
Member Author

@gabrielschulhof I was thinking that maybe we can first mark the TSFN as aborted(closed) and then call a method which will work like DispatchOne, say DispatchAll, that draining the queue of TSFN on the JavaScript thread. If the callee is on non-JavaScript thread we can notify them with a conditional variable if appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

No branches or pull requests

2 participants