Add async resource with hasRef
to threadsafe functions
#950
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, this creates a new object and a new
hasRef
function on it for every newly createdChannel
.Should we optimize this? We could create a single
hasRef
cached onInstanceData
since it usesthis
. This could possibly be further optimized by creating a class withhasRef
that is instantiated. Creating the async resource would look like:napi_get_instance_data
. Get the cachedNeonAsyncResource
class.napi_new_instance
. Create an instance of the class.napi_wrap
. Wrap the class with theArc<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