[−][src]Trait neon::task::Task
A Rust task that can be executed in a background thread.
Associated Types
type Output: Send + 'static
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
The task's error type, which is sent back to the main thread to communicate a task failure back to JavaScript.
type JsEvent: Value
The type of JavaScript value that gets produced to the asynchronous callback on the main thread after the task is completed.
Required methods
fn perform(&self) -> Result<Self::Output, Self::Error>
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<'a>(
self,
cx: TaskContext<'a>,
result: Result<Self::Output, Self::Error>
) -> JsResult<Self::JsEvent>
self,
cx: TaskContext<'a>,
result: Result<Self::Output, Self::Error>
) -> JsResult<Self::JsEvent>
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>)
Schedule a task to be executed on a background thread.
callback
should have the following signature:
function callback(err, value) {}