From 02daa900586a0287b761ff7b3b8d7e544370edec Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 24 Jan 2023 12:16:24 +0800 Subject: [PATCH] chore(napi): implement FromNapiValue for ThreadsafeFunction (#1447) --- crates/napi/src/threadsafe_function.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/napi/src/threadsafe_function.rs b/crates/napi/src/threadsafe_function.rs index a6e791b8..132dffe8 100644 --- a/crates/napi/src/threadsafe_function.rs +++ b/crates/napi/src/threadsafe_function.rs @@ -208,6 +208,12 @@ impl Clone for ThreadsafeFunction { } } +impl FromNapiValue for ThreadsafeFunction { + unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result { + Self::create(env, napi_val, 0, |ctx| Ok(vec![ctx.value])) + } +} + impl ThreadsafeFunction { /// See [napi_create_threadsafe_function](https://nodejs.org/api/n-api.html#n_api_napi_create_threadsafe_function) /// for more information.