pub struct Handle { /* private fields */ }Expand description
A handle to a tokio runtime that provides task spawning and execution capabilities.
This wrapper around tokio’s Handle maintains a weak reference to the parent runtime to enable proper I/O and timer driver access, particularly for signal handling.
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn block_on<F>(&self, future: F) -> <F as Future>::Outputwhere
F: Future,
pub fn block_on<F>(&self, future: F) -> <F as Future>::Outputwhere
F: Future,
Blocks on a future using the parent Runtime instead of Handle.
This ensures proper I/O and timer driver access for signal handling.
If the runtime has been dropped, falls back to the inner handle’s block_on.
Sourcepub fn spawn<T>(
&self,
future: impl Future<Output = T> + Send + 'static,
) -> JoinHandle<T>where
T: Send + 'static,
pub fn spawn<T>(
&self,
future: impl Future<Output = T> + Send + 'static,
) -> JoinHandle<T>where
T: Send + 'static,
Spawns a future onto the runtime.
Returns a JoinHandle that can be awaited to get the future’s result.
Sourcepub fn spawn_with_name<T>(
&self,
name: &str,
future: impl Future<Output = T> + Send + 'static,
) -> JoinHandle<T>where
T: Send + 'static,
pub fn spawn_with_name<T>(
&self,
name: &str,
future: impl Future<Output = T> + Send + 'static,
) -> JoinHandle<T>where
T: Send + 'static,
Spawns a named future onto the runtime.
The name is used for logging when trace-level logging is enabled.
Sourcepub fn spawn_blocking<T>(
&self,
f: impl FnOnce() -> T + Send + 'static,
) -> JoinHandle<T>where
T: Send + 'static,
pub fn spawn_blocking<T>(
&self,
f: impl FnOnce() -> T + Send + 'static,
) -> JoinHandle<T>where
T: Send + 'static,
Spawns a blocking task onto the runtime.
Returns a JoinHandle that can be awaited to get the task’s result.
Sourcepub fn spawn_blocking_with_name<T>(
&self,
name: &str,
f: impl FnOnce() -> T + Send + 'static,
) -> JoinHandle<T>where
T: Send + 'static,
pub fn spawn_blocking_with_name<T>(
&self,
name: &str,
f: impl FnOnce() -> T + Send + 'static,
) -> JoinHandle<T>where
T: Send + 'static,
Spawns a named blocking task onto the runtime.
The name is used for logging when trace-level logging is enabled.
Sourcepub fn spawn_local<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> JoinHandle<T>where
T: 'static,
pub fn spawn_local<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> JoinHandle<T>where
T: 'static,
Spawns a non-Send future onto the current thread.
This allows spawning futures that are not Send, which must run on the current thread.
Returns a JoinHandle that can be awaited to get the future’s result.
Sourcepub fn spawn_local_with_name<T>(
&self,
name: &str,
future: impl Future<Output = T> + 'static,
) -> JoinHandle<T>where
T: 'static,
pub fn spawn_local_with_name<T>(
&self,
name: &str,
future: impl Future<Output = T> + 'static,
) -> JoinHandle<T>where
T: 'static,
Spawns a named non-Send future onto the current thread.
The name is used for logging when trace-level logging is enabled.
Sourcepub fn current() -> Handle
pub fn current() -> Handle
Returns a handle to the currently running runtime.
§Panics
Panics if no runtime is currently running on this thread.