Handle

Struct Handle 

Source
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

Source

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

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);
Source

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

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

Source§

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)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Handle

§

impl !RefUnwindSafe for Handle

§

impl Send for Handle

§

impl Sync for Handle

§

impl Unpin for Handle

§

impl !UnwindSafe for Handle

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.