pub struct Handle { /* private fields */ }Expand description
A lightweight handle to a Runtime
Handle provides a way to interact with the runtime without having to clone the entire Runtime structure. It allows spawning tasks and blocking on futures.
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
Spawns a future onto the runtime
This method takes a future and begins executing it on the runtime, returning a JoinHandle that can be used to await its completion and retrieve its result.
§Type Parameters
F- The future type
§Parameters
future- The future to execute
§Returns
A JoinHandle that can be used to await the future’s completion
§Examples
use luminal::Runtime;
let rt = Runtime::new().unwrap();
let handle = rt.handle();
let task = handle.spawn(async {
println!("Running from a handle");
42
});
let result = handle.block_on(task);
assert_eq!(result, 42);Sourcepub fn block_on<F>(&self, future: F) -> F::Output
pub fn block_on<F>(&self, future: F) -> F::Output
Blocks the current thread until the provided future completes
This method takes a future and blocks the current thread until it completes, helping process other tasks while waiting to avoid deadlocks.
§Type Parameters
F- The future type
§Parameters
future- The future to execute and wait for
§Returns
The output of the future
§Examples
use luminal::Runtime;
let rt = Runtime::new().unwrap();
let handle = rt.handle();
let result = handle.block_on(async {
println!("Blocking using a handle");
42
});
assert_eq!(result, 42);Trait Implementations§
Source§impl Clone for Handle
impl Clone for Handle
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Creates a new handle referring to the same executor
This creates a lightweight clone that shares the same underlying executor as the original handle.
§Returns
A new Handle instance referring to the same executor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more