Struct neon::event::TaskBuilder
source · [−]pub struct TaskBuilder<'cx, C, E> { /* private fields */ }
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 |mut cx, greeting| Ok(cx.string(greeting)));
Ok(promise)
}
Implementations
sourceimpl<'a: 'cx, 'cx, C, O, E> TaskBuilder<'cx, C, E> where
C: Context<'a>,
O: Send + 'static,
E: FnOnce() -> O + Send + 'static,
impl<'a: 'cx, 'cx, C, O, E> TaskBuilder<'cx, C, E> where
C: Context<'a>,
O: Send + 'static,
E: FnOnce() -> O + Send + 'static,
sourcepub fn new(cx: &'cx mut C, execute: E) -> Self
pub fn new(cx: &'cx mut C, execute: E) -> Self
Construct a new task builder from an execute
callback that can be
scheduled to execute on the Node worker pool
sourcepub fn and_then<F>(self, complete: F) where
F: FnOnce(TaskContext<'_>, O) -> NeonResult<()> + Send + 'static,
pub fn and_then<F>(self, complete: F) where
F: FnOnce(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
sourcepub fn promise<V, F>(self, complete: F) -> Handle<'a, JsPromise> where
V: Value,
F: FnOnce(TaskContext<'_>, O) -> JsResult<'_, V> + Send + 'static,
pub fn promise<V, F>(self, complete: F) -> Handle<'a, JsPromise> where
V: Value,
F: FnOnce(TaskContext<'_>, O) -> JsResult<'_, V> + Send + 'static,
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
Auto Trait Implementations
impl<'cx, C, E> RefUnwindSafe for TaskBuilder<'cx, C, E> where
C: RefUnwindSafe,
E: RefUnwindSafe,
impl<'cx, C, E> Send for TaskBuilder<'cx, C, E> where
C: Send,
E: Send,
impl<'cx, C, E> Sync for TaskBuilder<'cx, C, E> where
C: Sync,
E: Sync,
impl<'cx, C, E> Unpin for TaskBuilder<'cx, C, E> where
E: Unpin,
impl<'cx, C, E> !UnwindSafe for TaskBuilder<'cx, C, E>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more