Struct deno_core::V8CrossThreadTaskSpawner
source · pub struct V8CrossThreadTaskSpawner { /* private fields */ }
Expand description
Allows for submission of v8 tasks on any thread.
Implementations§
source§impl V8CrossThreadTaskSpawner
impl V8CrossThreadTaskSpawner
sourcepub fn spawn<F>(&self, f: F)
pub fn spawn<F>(&self, f: F)
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
.
sourcepub fn spawn_blocking<'a, F, T>(&self, f: F) -> T
pub fn spawn_blocking<'a, F, T>(&self, f: F) -> T
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
impl Clone for V8CrossThreadTaskSpawner
source§fn clone(&self) -> V8CrossThreadTaskSpawner
fn clone(&self) -> V8CrossThreadTaskSpawner
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more