deno
deno copied to clipboard
valid usage of napi_ref_threadsafe_function can cause 100% cpu usage
Simple example like this causes a hot loop in Deno's implementation. The module continues to function, see below:
// from fsevents ...
CHECK(napi_create_threadsafe_function(env, argv[3], asyncResource, asyncName, 0, 2, NULL, NULL, NULL, fse_dispatch_event, &instance->callback) == napi_ok);
CHECK(napi_ref_threadsafe_function(env, instance->callback) == napi_ok);

We need to rethink use of event loop middleware. I think each tsfn should get a waker to the main thread instead.