neon::event

Struct 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§

Source§

impl<'a: 'cx, 'cx, C, O, E> TaskBuilder<'cx, C, E>
where C: Context<'a>, O: Send + 'static, E: FnOnce() -> O + Send + 'static,

Source

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

Source

pub fn and_then<F>(self, complete: F)
where F: FnOnce(Cx<'_>, O) -> NeonResult<()> + '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

Source

pub fn promise<V, F>(self, complete: F) -> Handle<'a, JsPromise>
where V: Value, F: FnOnce(Cx<'_>, O) -> JsResult<'_, V> + '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> Freeze for TaskBuilder<'cx, C, E>
where E: Freeze,

§

impl<'cx, C, E> RefUnwindSafe for TaskBuilder<'cx, C, E>

§

impl<'cx, C, E> Send for TaskBuilder<'cx, C, E>
where E: Send, C: Send,

§

impl<'cx, C, E> Sync for TaskBuilder<'cx, C, E>
where E: Sync, C: 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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.