node-addon-api
node-addon-api copied to clipboard
test: Add test coverage for "TSFN::Ref()"
We currently do not have a test for testing the Ref(Env env) function attached to the TSFN class. But I am not too sure if this is the best way to test this functionality. From what I understand this method is a wrapper around napi_ref_threadsafe_function which prevents the event loop from exiting until the tsfn gets destroyed by a call to Release().
My thought behind this approach is that we first reference this TSFN function, before the callback in setTimeout Unref's the TSFN which causes the event loop to exit. Though it appears that this tsfn should already be referenced prior to calling Ref, and napi_ref_threadsafe_function is idempotent so it has no effect. Is there a better approach to test this method? Also in what scenarios would napi_ref_threadsafe_function or TSFN::Ref() be used? Thanks!