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§
Source§impl<'a: 'cx, 'cx, C, O, E> TaskBuilder<'cx, C, E>
impl<'a: 'cx, 'cx, C, O, E> TaskBuilder<'cx, C, E>
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)
pub fn and_then<F>(self, complete: F)
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>
pub fn promise<V, F>(self, complete: F) -> Handle<'a, JsPromise>
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> Freeze for TaskBuilder<'cx, C, E>where
E: Freeze,
impl<'cx, C, E> RefUnwindSafe for TaskBuilder<'cx, C, E>where
E: RefUnwindSafe,
C: RefUnwindSafe,
impl<'cx, C, E> Send for TaskBuilder<'cx, C, E>
impl<'cx, C, E> Sync for TaskBuilder<'cx, C, E>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more