fix(napi): callback should be Fn rather than FnOnce (#2749)

In ThreadsafeFunction::call_with_return_value
This commit is contained in:
LongYinan 2025-06-28 06:57:54 -07:00 committed by GitHub
parent b25c5de30c
commit 56998d5f12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -463,14 +463,17 @@ impl<T: FromNapiValue + 'static> futures_core::Stream for Reader<T> {
None => return Poll::Ready(None),
}
}
let waker = cx.waker().clone();
let state = self.state.clone();
let state_in_catch = state.clone();
let waker = cx.waker().clone();
self.inner.call_with_return_value(
Ok(()),
ThreadsafeFunctionCallMode::NonBlocking,
move |iterator, _| {
let iterator = iterator?;
let state = state.clone();
let state_in_catch = state_in_catch.clone();
let waker = waker.clone();
iterator
.then(move |cx| {
if cx.value.done {

View File

@ -481,7 +481,7 @@ impl<
}
/// Call the ThreadsafeFunction, and handle the return value with a callback
pub fn call_with_return_value<F: 'static + FnOnce(Result<Return>, Env) -> Result<()>>(
pub fn call_with_return_value<F: 'static + Fn(Result<Return>, Env) -> Result<()>>(
&self,
value: Result<T, ErrorStatus>,
mode: ThreadsafeFunctionCallMode,
@ -590,7 +590,7 @@ impl<
}
/// Call the ThreadsafeFunction, and handle the return value with a callback
pub fn call_with_return_value<F: 'static + FnOnce(Result<Return>, Env) -> Result<()>>(
pub fn call_with_return_value<F: 'static + Fn(Result<Return>, Env) -> Result<()>>(
&self,
value: T,
mode: ThreadsafeFunctionCallMode,