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

Add async resource with hasRef to threadsafe functions #950

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kjvalencik
Copy link
Member

@kjvalencik kjvalencik commented Nov 29, 2022

Currently, this creates a new object and a new hasRef function on it for every newly created Channel.

Should we optimize this? We could create a single hasRef cached on InstanceData since it uses this. This could possibly be further optimized by creating a class with hasRef that is instantiated. Creating the async resource would look like:

  • napi_get_instance_data. Get the cached NeonAsyncResource class.
  • napi_new_instance. Create an instance of the class.
  • napi_wrap. Wrap the class with the Arc<Mutex<State>> data.
  • napi_type_tag. Type tag for safety when unwrapping.

It might be worth using #[track_caller] and track the line number in the resource name. That might help users find out which TSFN is keeping things up.

Resolves #948

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.

Jest and why-is-node-running reports open handle on exit due to InstanceData.drop_queue's threadsafe function
1 participant