Skip to main content

RuntimeHandle

Struct RuntimeHandle 

Source
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

Source

pub fn enter(&self) -> EnterGuard<'_>

Sets the handle’s runtime on the calling thread until the guard drops.

Source

pub fn id(&self) -> RuntimeId

The runtime’s id.

Source

pub fn try_current() -> Result<Self, TryCurrentError>

The handle of the runtime set on this thread (inside its block_on, on one of its workers, or under enter); unlike current it never falls back to the default runtime.

Source§

impl RuntimeHandle

Source

pub fn workers(&self) -> usize

The workers the runtime has started, stopped ones included: the indices spawn_on_worker takes are 0..workers().

Source

pub fn spawn_on_worker<F>( &self, worker: usize, future: F, ) -> Result<Task<F::Output>>
where F: Future + Send + 'static, F::Output: Send + 'static,

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.

Source

pub fn spawn_local_on_worker<M, F>( &self, worker: usize, make: M, ) -> Result<Task<F::Output>>
where M: FnOnce() -> F + Send + 'static, F: Future + 'static, F::Output: Send + 'static,

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.

Source

pub fn on_each_worker<M, F>(&self, make: M) -> JoinSet<F::Output>
where M: Fn() -> F + Send + Sync + 'static, F: Future + 'static, F::Output: Send + 'static,

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

Source

pub fn stats(&self) -> Stats

A snapshot of the counters of the handle’s runtime; see Runtime::stats.

Source§

impl RuntimeHandle

Source

pub fn block_on<F: Future>(&self, future: F) -> F::Output

Runs future to its end on the calling thread; see block_on.

Source

pub fn spawn<F>(&self, future: F) -> Task<F::Output> ⓘ
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawns a task on one of the runtime’s shards; see spawn.

Source

pub fn spawn_blocking<F, T>(&self, f: F) -> Task<T> ⓘ
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Runs f on the runtime’s blocking pool; see spawn_blocking.

Source

pub fn current() -> Self

The handle of the runtime this thread is inside, or of the default runtime (started now if it is not running yet).

Trait Implementations§

Source§

impl Clone for RuntimeHandle

Source§

fn clone(&self) -> RuntimeHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RuntimeHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

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.