ScopedTask

Trait ScopedTask 

Source
pub trait ScopedTask<'task>: Send + Sized {
    type Output: Send + Sized + 'static;
    type JsValue: ToNapiValue + TypeName;

    // Required methods
    fn compute(&mut self) -> Result<Self::Output>;
    fn resolve(
        &mut self,
        env: &'task Env,
        output: Self::Output,
    ) -> Result<Self::JsValue>;

    // Provided methods
    fn reject(&mut self, env: &'task Env, err: Error) -> Result<Self::JsValue> { ... }
    fn finally(self, env: Env) -> Result<()> { ... }
}
Expand description

Basically it’s the same as the Task trait

The difference is it can be resolve or reject a JsValue with lifetime

Required Associated Types§

Required Methods§

Source

fn compute(&mut self) -> Result<Self::Output>

Compute logic in libuv thread

Source

fn resolve( &mut self, env: &'task Env, output: Self::Output, ) -> Result<Self::JsValue>

Into this method if compute return Ok

Provided Methods§

Source

fn reject(&mut self, env: &'task Env, err: Error) -> Result<Self::JsValue>

Into this method if compute return Err

Source

fn finally(self, env: Env) -> Result<()>

after resolve or reject

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, T: Task> ScopedTask<'a> for T

Source§

type Output = <T as Task>::Output

Source§

type JsValue = <T as Task>::JsValue