Skip to main content

Runtime

Struct Runtime 

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

Single-threaded async runtime.

§Examples

use nexus_async_rt::{Runtime, spawn_boxed, spawn_slab};
use nexus_slab::byte::unbounded::Slab;
use nexus_rt::WorldBuilder;

let mut world = WorldBuilder::new().build();

// Simple — Box-allocated tasks
let mut rt = Runtime::new(&mut world);
rt.block_on(async {
    spawn_boxed(async { /* Box-allocated */ });
});

// With slab for hot-path tasks
let slab = unsafe { Slab::<256>::with_chunk_capacity(64) };
let mut rt = Runtime::builder(&mut world)
    .slab_unbounded(slab)
    .build();
rt.block_on(async {
    spawn_boxed(async { /* Box-allocated */ });
    spawn_slab(async { /* slab-allocated */ });
});

Implementations§

Source§

impl Runtime

Source

pub fn new(world: &mut World) -> Self

Create a runtime with default settings. Box-allocated tasks only.

For slab allocation or custom configuration, use Runtime::builder.

Source

pub fn builder(world: &mut World) -> RuntimeBuilder<'_>

Create a runtime via the builder pattern.

Source

pub fn shutdown_handle(&self) -> ShutdownHandle

Returns a ShutdownHandle for triggering or observing shutdown.

Source

pub fn install_signal_handlers(&self)

Install signal handlers for SIGTERM and SIGINT.

Source

pub fn task_count(&self) -> usize

Number of live spawned tasks.

Source§

impl Runtime

Source

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

Drive the root future to completion. CPU-friendly.

Parks the thread when no work is available.

Source

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

Drive the root future to completion. Busy-wait.

Never parks. Minimum wake latency at 100% CPU.

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> 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, 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.