pub struct Handle { /* private fields */ }Expand description
A thread-safe handle used to schedule work on a runtime.
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn current() -> Handle
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.
Sourcepub fn notify(&self) -> Result<()>
pub fn notify(&self) -> Result<()>
Wakes the runtime’s driver.
Returns notification errors to the caller without retrying, unlike internal scheduler notifications.
Sourcepub fn busy_duration(&self) -> Option<Duration>
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.
Sourcepub fn current_turn(&self) -> Option<Duration>
pub fn current_turn(&self) -> Option<Duration>
Returns how long the current runtime turn has been running, None
while the runtime is idle.
Sourcepub fn poll_count(&self) -> Option<u64>
pub fn poll_count(&self) -> Option<u64>
Returns the number of scheduler polls, including polls with no ready tasks.
See Runtime::poll_count. Always returns Some.
Sourcepub fn poll_again_count(&self) -> Option<u64>
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.
Sourcepub fn self_wake_count(&self) -> Option<u64>
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.
Sourcepub fn current_task(&self) -> Option<&'static Location<'static>>
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.
Sourcepub fn poll_histogram(&self) -> Option<Histogram>
pub fn poll_histogram(&self) -> Option<Histogram>
Returns the histogram of runtime poll durations.
See Runtime::poll_histogram. Always returns Some.
Sourcepub fn spawn<F>(&self, future: F) -> RemoteJoinHandle<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> RemoteJoinHandle<F::Output> ⓘ
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.
Both the future and output must be Send, including submissions from the
runtime’s own thread, which use the local fast path. Accepted futures
are polled and dropped on the runtime thread; the output is transferred
to the caller through the join handle.
The returned join handle is neither Send nor Sync; dropping it
detaches the task. Submissions rejected after shutdown are never polled
and their futures may be dropped on the submitting thread. This low-level
method does not apply registered task callbacks.
let task = hnd.spawn(async { 42 });
assert_eq!(task.await.unwrap(), 42);Sourcepub fn spawn_detached<F>(&self, future: F)
pub fn spawn_detached<F>(&self, future: F)
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.
The future must be Send, even when submitted on the owner thread.
Rejected submissions are never polled and their futures may be dropped
on the submitting thread. Registered task callbacks are not applied.