2020-12-18 11:32:07 +08:00
|
|
|
use crate::{js_values::NapiValue, Env, Error, Result};
|
2020-05-11 00:28:06 +08:00
|
|
|
|
2020-12-18 11:32:07 +08:00
|
|
|
pub trait Task: Send + Sized {
|
2020-05-12 13:59:20 +08:00
|
|
|
type Output: Send + Sized + 'static;
|
2020-06-21 19:10:06 +08:00
|
|
|
type JsValue: NapiValue;
|
2020-05-11 00:28:06 +08:00
|
|
|
|
2020-12-18 11:32:07 +08:00
|
|
|
/// Compute logic in libuv thread
|
2020-06-19 16:19:06 +08:00
|
|
|
fn compute(&mut self) -> Result<Self::Output>;
|
2020-05-11 00:28:06 +08:00
|
|
|
|
2020-12-18 11:32:07 +08:00
|
|
|
/// Into this method if `compute` return `Ok`
|
2020-09-28 00:27:37 +08:00
|
|
|
fn resolve(self, env: Env, output: Self::Output) -> Result<Self::JsValue>;
|
2020-12-18 11:32:07 +08:00
|
|
|
|
|
|
|
/// Into this method if `compute` return `Err`
|
|
|
|
fn reject(self, _env: Env, err: Error) -> Result<Self::JsValue> {
|
|
|
|
Err(err)
|
|
|
|
}
|
2020-05-11 00:28:06 +08:00
|
|
|
}
|