mirror of
https://github.com/napi-rs/napi-rs.git
synced 2025-12-08 19:56:07 +00:00
* feat(napi): support to use tuple with either (#1993) `Either` uses `ValidateNapiValue` + `TypeName` to validate and report error on value not being matched. So there's no way to remove these super traits from it. So I implemented these types to `Tuple` types. * feat(napi): support `Return` generic of ThreadsafeFunction * depracate JsFunction * CalleeHandled tsfn should handle Result in callback * Pass env to call_with_return_value callback * Fix compile * clippy fix * Fix electron test * Function args --------- Co-authored-by: Hana <andywangsy@gmail.com>
28 lines
705 B
Rust
28 lines
705 B
Rust
use crate::{
|
|
bindgen_runtime::{ToNapiValue, TypeName},
|
|
Env, Error, Result,
|
|
};
|
|
|
|
pub trait Task: Send + Sized {
|
|
type Output: Send + Sized + 'static;
|
|
type JsValue: ToNapiValue + TypeName;
|
|
|
|
/// Compute logic in libuv thread
|
|
fn compute(&mut self) -> Result<Self::Output>;
|
|
|
|
/// Into this method if `compute` return `Ok`
|
|
fn resolve(&mut self, env: Env, output: Self::Output) -> Result<Self::JsValue>;
|
|
|
|
#[allow(unused_variables)]
|
|
/// Into this method if `compute` return `Err`
|
|
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
|
|
Err(err)
|
|
}
|
|
|
|
#[allow(unused_variables)]
|
|
/// after resolve or reject
|
|
fn finally(&mut self, env: Env) -> Result<()> {
|
|
Ok(())
|
|
}
|
|
}
|