2021-11-02 21:36:34 +09:00
|
|
|
use crate::{
|
|
|
|
bindgen_runtime::{ToNapiValue, TypeName},
|
|
|
|
Env, Error, Result,
|
|
|
|
};
|
2020-05-11 01:28:06 +09:00
|
|
|
|
2020-12-18 12:32:07 +09:00
|
|
|
pub trait Task: Send + Sized {
|
2020-05-12 14:59:20 +09:00
|
|
|
type Output: Send + Sized + 'static;
|
2021-11-02 21:36:34 +09:00
|
|
|
type JsValue: ToNapiValue + TypeName;
|
2020-05-11 01:28:06 +09:00
|
|
|
|
2020-12-18 12:32:07 +09:00
|
|
|
/// Compute logic in libuv thread
|
2020-06-19 17:19:06 +09:00
|
|
|
fn compute(&mut self) -> Result<Self::Output>;
|
2020-05-11 01:28:06 +09:00
|
|
|
|
2020-12-18 12:32:07 +09:00
|
|
|
/// Into this method if `compute` return `Ok`
|
2020-09-28 01:27:37 +09:00
|
|
|
fn resolve(self, env: Env, output: Self::Output) -> Result<Self::JsValue>;
|
2020-12-18 12:32:07 +09:00
|
|
|
|
|
|
|
/// Into this method if `compute` return `Err`
|
|
|
|
fn reject(self, _env: Env, err: Error) -> Result<Self::JsValue> {
|
|
|
|
Err(err)
|
|
|
|
}
|
2021-11-02 21:36:34 +09:00
|
|
|
|
|
|
|
// after resolve or reject
|
|
|
|
fn finally() {}
|
2020-05-11 01:28:06 +09:00
|
|
|
}
|