Skip to main content

Handle

Struct Handle 

Source
pub struct Handle { /* private fields */ }
Expand description

A thread-safe handle used to schedule work on a runtime.

Implementations§

Source§

impl Handle

Source

pub fn current() -> Handle

Returns a handle to the runtime active on the current thread.

§Panics

Panics if no runtime is active on the current thread.

Source

pub fn notify(&self) -> Result<()>

Wakes the runtime’s driver.

Returns notification errors to the caller without retrying, unlike internal scheduler notifications.

Source

pub fn busy_duration(&self) -> Option<Duration>

Returns the total time the runtime has been busy.

See Runtime::busy_duration. Always returns Some, the return type matches the other runtime backends.

Source

pub fn current_turn(&self) -> Option<Duration>

Returns how long the current runtime turn has been running, None while the runtime is idle.

See Runtime::current_turn.

Source

pub fn poll_count(&self) -> Option<u64>

Returns the number of runtime polls that ran scheduled tasks.

See Runtime::poll_count. Always returns Some.

Source

pub fn poll_again_count(&self) -> Option<u64>

Returns the number of runtime polls that left scheduled tasks.

See Runtime::poll_again_count. Always returns Some.

Source

pub fn self_wake_count(&self) -> Option<u64>

Returns the number of times a task woke itself while it was polled.

See Runtime::self_wake_count. Always returns Some.

Source

pub fn current_task(&self) -> Option<&'static Location<'static>>

Returns the spawn location of the task the runtime is polling.

Returns None while the runtime is idle, handles driver events or between tasks. Can be read from other threads, for example to name the task that blocks a stalled runtime.

Source

pub fn poll_histogram(&self) -> Option<Histogram>

Returns the histogram of runtime poll durations.

See Runtime::poll_histogram. Always returns Some.

Source

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

Spawns a task on the handle’s runtime and returns a RemoteJoinHandle.

Spawning a task enables the task to execute concurrently to other tasks. There is no guarantee that a spawned task will execute to completion.

On the runtime thread the task is spawned directly. From other threads the future and output must be Send, the future is polled and dropped on the runtime thread and its output is returned through the handle. The handle is neither Send nor Sync, dropping it detaches the task.

let task = hnd.spawn(async { 42 });
assert_eq!(task.await.unwrap(), 42);
Source

pub fn spawn_detached<F>(&self, future: F)
where F: Future + Send + 'static,

Spawns a new asynchronous task without a join handle.

The output is dropped on the runtime thread when the task completes, so it does not have to be Send.

Trait Implementations§

Source§

impl Clone for Handle

Source§

fn clone(&self) -> Self

Shares the runtime’s queue without creating another runtime.

1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Handle

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.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.