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>) { ... } }
Expand description
A Rust task that can be executed in the background on the Node thread pool.
Associated Types
type Output: Send + 'static
[src]
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.
Required methods
fn perform(&self) -> Result<Self::Output, Self::Error>
[src]
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]
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.
Provided methods
fn schedule(self, callback: Handle<'_, JsFunction>)
[src]
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) {}