pub type JsCallback<Args = (), Ret = ()> = Arc<ThreadsafeFunction<Args, Either<Ret, InvalidReturnValue>, Args, Status, false, true>>;Expand description
JsCallback is a type alias for a weak, caller-handled
ThreadsafeFunction whose return value is validated in Rust: it
represents a JavaScript function passed to the Rust side.
- Rust:
JsCallback<FnArgs<(u32, f64)>, Promise<()>> - JS:
(id: number, ms: number) => Promise<void>
The Weak = true parameter means the callback does not keep its owning
event loop alive, which is exactly what the host protocol needs: a worker
that registered a timer or task host may exit at any time, and the runtime
detects that through the threadsafe function’s aborted flag instead of
pinning the worker.
Aliased Type§
pub struct JsCallback<Args = (), Ret = ()> { /* private fields */ }