Skip to content

Commit

Permalink
tsfn ref & unref
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Jan 20, 2023
1 parent 1ce0aea commit b013fbd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/emnapi/src/emnapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ _emnapi_tsfn_create(napi_env env,
_emnapi_env_ref(env);

EMNAPI_KEEPALIVE_PUSH();
_emnapi_ctx_increase_waiting_request_counter();
ts_fn->async_ref = true;
return ts_fn;
}
Expand Down Expand Up @@ -560,6 +561,7 @@ static void _emnapi_tsfn_destroy(napi_threadsafe_function func) {
_emnapi_env_unref(func->env);
if (func->async_ref) {
EMNAPI_KEEPALIVE_POP();
_emnapi_ctx_decrease_waiting_request_counter();
func->async_ref = false;
}

Expand Down Expand Up @@ -923,6 +925,7 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func) {
#ifdef __EMSCRIPTEN_PTHREADS__
if (func->async_ref) {
EMNAPI_KEEPALIVE_POP();
_emnapi_ctx_decrease_waiting_request_counter();
func->async_ref = false;
}
return napi_ok;
Expand All @@ -936,6 +939,7 @@ napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func) {
#ifdef __EMSCRIPTEN_PTHREADS__
if (!func->async_ref) {
EMNAPI_KEEPALIVE_PUSH();
_emnapi_ctx_increase_waiting_request_counter();
func->async_ref = true;
}
return napi_ok;
Expand Down

0 comments on commit b013fbd

Please sign in to comment.