You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ability to synchronously drain a thread safe function #31531
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 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.
@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.
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
Activity
gabrielschulhof commentedon Jan 28, 2020
@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 commentedon Jan 29, 2020
@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, sayDispatchAll, that draining thequeueof TSFN on the JavaScript thread. If the callee is on non-JavaScript thread we can notify them with a conditional variable if appropriate.github-actions commentedon Jun 27, 2026
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
github-actions commentedon Jul 28, 2026
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.