Skip to content

Ability to synchronously drain a thread safe function #31531

Closed as not planned
Closed as not planned

Description

@legendecas

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.

Activity

  1. gabrielschulhof commented on Jan 28, 2020

    @gabrielschulhof
    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.

  2. legendecas commented on Jan 29, 2020

    @legendecas
    MemberAuthor

    @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.

  3. github-actions commented on Jun 27, 2026

    @github-actions
    Contributor

    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.

  4. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 27, 2026
  5. github-actions commented on Jul 28, 2026

    @github-actions
    Contributor

    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.

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

    node-apiIssues and PRs related to Node-API.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions