pub struct RuntimeHandle { /* private fields */ }Expand description
A cloneable handle to a Runtime, to spawn on it from anywhere. It
does not keep the runtime running.
Implementations§
Source§impl RuntimeHandle
impl RuntimeHandle
Sourcepub fn enter(&self) -> EnterGuard<'_>
pub fn enter(&self) -> EnterGuard<'_>
Sets the handle’s runtime on the calling thread until the guard drops.
Sourcepub fn try_current() -> Result<Self, TryCurrentError>
pub fn try_current() -> Result<Self, TryCurrentError>
Source§impl RuntimeHandle
impl RuntimeHandle
Sourcepub fn workers(&self) -> usize
pub fn workers(&self) -> usize
The workers the runtime has started, stopped ones included: the
indices spawn_on_worker takes are
0..workers().
Sourcepub fn spawn_on_worker<F>(
&self,
worker: usize,
future: F,
) -> Result<Task<F::Output>>
pub fn spawn_on_worker<F>( &self, worker: usize, future: F, ) -> Result<Task<F::Output>>
Spawns future on worker worker, where it stays: a handoff of the
worker’s shard moves the task with it, so it runs on that worker for
its whole life.
§Errors
InvalidInput when the runtime has no such worker, or the worker
stopped (or is stopping) and takes no new task.
Sourcepub fn spawn_local_on_worker<M, F>(
&self,
worker: usize,
make: M,
) -> Result<Task<F::Output>>
pub fn spawn_local_on_worker<M, F>( &self, worker: usize, make: M, ) -> Result<Task<F::Output>>
Runs make on worker worker and spawns the future it makes there,
which need not be Send: it stays on the thread that made it, as a
spawn_local task does.
A handoff of the worker’s shard leaves such a future on the thread
that made it, off the worker: it finishes there, where
worker_index answers None and shard-local
values are out of reach. The handle is that of the task that makes
the future on the worker and waits for it: its id is not the one
task::id answers inside the future, and dropping
it cancels both.
§Errors
As for spawn_on_worker.
Sourcepub fn on_each_worker<M, F>(&self, make: M) -> JoinSet<F::Output>
pub fn on_each_worker<M, F>(&self, make: M) -> JoinSet<F::Output>
Runs make on every worker that takes tasks and spawns the future it
makes there, as spawn_local_on_worker
does: the set holds one task per worker. A runtime with no worker
gives an empty set.
Source§impl RuntimeHandle
impl RuntimeHandle
Sourcepub fn stats(&self) -> Stats
pub fn stats(&self) -> Stats
A snapshot of the counters of the handle’s runtime; see
Runtime::stats.
Source§impl RuntimeHandle
impl RuntimeHandle
Sourcepub fn block_on<F: Future>(&self, future: F) -> F::Output
pub fn block_on<F: Future>(&self, future: F) -> F::Output
Runs future to its end on the calling thread; see block_on.
Sourcepub fn spawn<F>(&self, future: F) -> Task<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> Task<F::Output> ⓘ
Spawns a task on one of the runtime’s shards; see spawn.
Sourcepub fn spawn_blocking<F, T>(&self, f: F) -> Task<T> ⓘ
pub fn spawn_blocking<F, T>(&self, f: F) -> Task<T> ⓘ
Runs f on the runtime’s blocking pool; see spawn_blocking.
Trait Implementations§
Source§impl Clone for RuntimeHandle
impl Clone for RuntimeHandle
Source§fn clone(&self) -> RuntimeHandle
fn clone(&self) -> RuntimeHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more