Runtime

Struct Runtime 

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

Main runtime for executing async tasks

The Runtime is the central coordination point for the Luminal async runtime. It provides methods for spawning tasks, blocking on futures, and managing the runtime itself. Unlike tokio, this runtime is safe to pass across DLL boundaries as it doesn’t rely on thread-local storage.

Implementations§

Source§

impl Runtime

Source

pub fn new() -> Result<Self, RuntimeError>

Creates a new Luminal runtime

This initializes a new multi-threaded runtime with a work-stealing scheduler using the number of available CPU cores. The runtime will create worker threads and begin processing the task queue immediately.

§Returns

A new Runtime instance wrapped in a Result

§Errors

Returns an error if the runtime could not be initialized

§Example
use luminal::Runtime;

let rt = Runtime::new().unwrap();
rt.block_on(async {
    println!("Running on Luminal runtime!");
});
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

§Example
use luminal::Runtime;

let rt = Runtime::new().unwrap();
let handle = rt.spawn(async {
    // Some async work
    42
});

let result = rt.block_on(handle); // Waits for the result
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

§Example
use luminal::Runtime;

let rt = Runtime::new().unwrap();
let result = rt.block_on(async {
    // Some async work
    42
});
assert_eq!(result, 42);
Source

pub fn handle(&self) -> Handle

Returns a Handle to this runtime

The Handle provides a lightweight way to interact with the runtime without cloning the entire Runtime.

§Returns

A new Handle to this runtime

§Example
use luminal::Runtime;

let rt = Runtime::new().unwrap();
let handle = rt.handle();

// Use the handle to spawn tasks
let task = handle.spawn(async { 42 });
Source

pub fn stats(&self) -> (usize, usize)

Returns statistics about the runtime

§Returns

A tuple containing the current queue length and the number of tasks processed

§Example
use luminal::Runtime;

let rt = Runtime::new().unwrap();
let (queue_len, tasks_processed) = rt.stats();
println!("Queue length: {}, Tasks processed: {}", queue_len, tasks_processed);

Trait Implementations§

Source§

impl Clone for Runtime

Source§

fn clone(&self) -> Self

Creates a new runtime referring to the same executor

This allows for lightweight cloning of the runtime, as the underlying executor is reference-counted.

§Returns

A new Runtime 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§

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.