pub struct V8CrossThreadTaskSpawner { /* private fields */ }
Expand description

Allows for submission of v8 tasks on any thread.

Implementations§

source§

impl V8CrossThreadTaskSpawner

source

pub fn spawn<F>(&self, f: F)
where F: FnOnce(&mut HandleScope<'_>) + Send + 'static,

Spawn a task that runs within the crate::JsRuntime event loop, potentially (but not required to be) from a different thread than the runtime is running on.

The task is handed off to be run the next time the event loop is polled, and there are no guarantees as to when this may happen.

Safety

The task shares the same v8::HandleScope as the core event loop, which means that it must maintain the scope in a valid state to avoid corrupting or destroying the runtime.

For example, if the code called by this task can raise an exception, the task must ensure that it calls that code within a new v8::TryCatch to avoid the exception leaking to the event loop’s v8::HandleScope.

source

pub fn spawn_blocking<'a, F, T>(&self, f: F) -> T
where F: FnOnce(&mut HandleScope<'_>) -> T + Send + 'a, T: Send + 'a,

Spawn a task that runs within the crate::JsRuntime event loop from a different thread than the runtime is running on.

This function will deadlock if called from the same thread as the crate::JsRuntime, and there are no checks for this case.

As this function blocks until the task has run to completion (or panics/deadlocks), it is safe to borrow data from the local environment and use it within the closure.

The task is handed off to be run the next time the event loop is polled, and there are no guarantees as to when this may happen, however the function will not return until the task has been fully run to completion.

Safety

The task shares the same v8::HandleScope as the core event loop, which means that it must maintain the scope in a valid state to avoid corrupting or destroying the runtime.

For example, if the code called by this task can raise an exception, the task must ensure that it calls that code within a new v8::TryCatch to avoid the exception leaking to the event loop’s v8::HandleScope.

Trait Implementations§

source§

impl Clone for V8CrossThreadTaskSpawner

source§

fn clone(&self) -> V8CrossThreadTaskSpawner

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Send for V8CrossThreadTaskSpawner

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.