Struct neon::event::TaskBuilder [−][src]
pub struct TaskBuilder<'cx, C, E> { /* fields omitted */ }
This is supported on crate feature
task-api
only.Expand description
Node asynchronous task builder
fn greet(mut cx: FunctionContext) -> JsResult<JsPromise> {
let name = cx.argument::<JsString>(0)?.value(&mut cx);
let promise = cx
.task(move || format!("Hello, {}!", name))
.promise(move |cx, greeting| Ok(cx.string(greeting)));
Ok(promise)
}
Implementations
Construct a new task builder from an execute
callback that can be
scheduled to execute on the Node worker pool
pub fn and_then<F>(self, complete: F) where
F: FnOnce(&mut TaskContext<'_>, O) -> NeonResult<()> + Send + 'static,
pub fn and_then<F>(self, complete: F) where
F: FnOnce(&mut TaskContext<'_>, O) -> NeonResult<()> + Send + 'static,
Schedules a task to execute on the Node worker pool, executing the
complete
callback on the JavaScript main thread with the result
of the execute
callback
pub fn promise<V, F>(self, complete: F) -> Handle<'a, JsPromise> where
V: Value,
for<'b> F: FnOnce(&mut TaskContext<'b>, O) -> JsResult<'b, V> + Send + 'static,
This is supported on crate feature promise-api
only.
pub fn promise<V, F>(self, complete: F) -> Handle<'a, JsPromise> where
V: Value,
for<'b> F: FnOnce(&mut TaskContext<'b>, O) -> JsResult<'b, V> + Send + 'static,
This is supported on crate feature
promise-api
only.Schedules a task to execute on the Node worker pool and returns a
promise that is resolved with the value from the complete
callback.
The complete
callback will execute on the JavaScript main thread and
is passed the return value from execute
. If the complete
callback
throws, the promise will be rejected with the exception