2020-12-18 12:32:07 +09:00
|
|
|
use crate::{js_values::NapiValue, 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;
|
2020-06-21 20:10:06 +09:00
|
|
|
type JsValue: NapiValue;
|
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)
|
|
|
|
}
|
2020-05-11 01:28:06 +09:00
|
|
|
}
|