Trait neon::task::Task[][src]

pub trait Task: Send + Sized + 'static {
    type Output: Send + 'static;
    type Error: Send + 'static;
    type JsEvent: Value;
    fn perform(&self) -> Result<Self::Output, Self::Error>;
fn complete(
        self,
        cx: TaskContext<'_>,
        result: Result<Self::Output, Self::Error>
    ) -> JsResult<'_, Self::JsEvent>; fn schedule(self, callback: Handle<'_, JsFunction>) { ... } }

A Rust task that can be executed in the background on the Node thread pool.

Associated Types

type Output: Send + 'static[src]

The task’s result type, which is sent back to the main thread to communicate a successful result back to JavaScript.

type Error: Send + 'static[src]

The task’s error type, which is sent back to the main thread to communicate a task failure back to JavaScript.

type JsEvent: Value[src]

The type of JavaScript value that gets produced to the asynchronous callback on the main thread after the task is completed.

Loading content...

Required methods

fn perform(&self) -> Result<Self::Output, Self::Error>[src]

Perform the task, producing either a successful Output or an unsuccessful Error. This method is executed in a background thread as part of libuv’s built-in thread pool.

fn complete(
    self,
    cx: TaskContext<'_>,
    result: Result<Self::Output, Self::Error>
) -> JsResult<'_, Self::JsEvent>
[src]

Convert the result of the task to a JavaScript value to be passed to the asynchronous callback. This method is executed on the main thread at some point after the background task is completed.

Loading content...

Provided methods

fn schedule(self, callback: Handle<'_, JsFunction>)[src]

Schedule a task to be executed on a background thread.

callback should have the following signature:

function callback(err, value) {}
Loading content...

Implementors

Loading content...