Skip to main content

RuntimeBuilder

Struct RuntimeBuilder 

Source
pub struct RuntimeBuilder<'w> { /* private fields */ }
Expand description

Builder for configuring a Runtime.

§Examples

use nexus_async_rt::*;
use nexus_slab::byte::unbounded::Slab;

let mut world = nexus_rt::WorldBuilder::new().build();
let slab = unsafe { Slab::<256>::with_chunk_capacity(64) };

let mut rt = Runtime::builder(&mut world)
    .tasks_per_cycle(128)
    .slab_unbounded(slab)
    .signal_handlers(true)
    .build();

Implementations§

Source§

impl<'w> RuntimeBuilder<'w>

Source

pub fn tasks_per_cycle(self, limit: usize) -> Self

Maximum tasks polled per cycle before yielding to check IO. Default: 64.

Source

pub fn event_interval(self, n: u32) -> Self

Number of loop iterations between non-blocking IO driver polls. Default: 61 (matches tokio’s heuristic).

Every event_interval iterations the runtime does a non-blocking epoll_wait(0) to check for socket events, even if tasks are ready. Lower values improve IO responsiveness at the cost of more syscalls; higher values favor task throughput.

Source

pub fn cross_thread_drain_limit(self, limit: usize) -> Self

Maximum cross-thread wakes drained per poll cycle. Default: unlimited.

Caps how many tasks woken from other threads are moved into the local ready queue per iteration. Prevents a firehose of cross-thread wakes from starving local tasks and IO. Remaining wakes are drained on the next iteration.

Source

pub fn queue_capacity(self, cap: usize) -> Self

Pre-allocated capacity for internal queues. Default: 64.

Source

pub fn event_capacity(self, cap: usize) -> Self

Maximum IO events processed per epoll cycle. Default: 1024.

Source

pub fn token_capacity(self, cap: usize) -> Self

Initial number of IO source slots. Default: 64.

Source

pub fn signal_handlers(self, enable: bool) -> Self

Install SIGTERM/SIGINT signal handlers. Default: false.

Source

pub fn slab_unbounded<const S: usize>(self, slab: Slab<S>) -> Self

Hand off a growable (unbounded) slab for spawn_slab.

S is the total slot size in bytes. The task header uses 72 bytes, so Slab<256> gives 184 bytes for the future. Most async IO futures are 128–256 bytes — Slab<256> or Slab<512> covers the common cases.

The slab grows by allocating new chunks when full. No task spawn will ever fail due to capacity.

§Examples
use nexus_slab::byte::unbounded::Slab;

// SAFETY: single-threaded runtime.
let slab = unsafe { Slab::<256>::with_chunk_capacity(64) };

let mut rt = Runtime::builder(&mut world)
    .slab_unbounded(slab)
    .build();
Source

pub fn slab_bounded<const S: usize>(self, slab: Slab<S>) -> Self

Hand off a fixed-capacity (bounded) slab for spawn_slab.

S is the total slot size in bytes. The slab has a fixed number of slots — spawn_slab panics if the slab is full. Use this when you want deterministic memory usage and know the maximum number of concurrent hot-path tasks.

§Examples
use nexus_slab::byte::bounded::Slab;

// SAFETY: single-threaded runtime.
let slab = unsafe { Slab::<256>::with_capacity(64) };

let mut rt = Runtime::builder(&mut world)
    .slab_bounded(slab)
    .build();
Source

pub fn build(self) -> Runtime

Build the runtime.

Auto Trait Implementations§

§

impl<'w> Freeze for RuntimeBuilder<'w>

§

impl<'w> !RefUnwindSafe for RuntimeBuilder<'w>

§

impl<'w> !Send for RuntimeBuilder<'w>

§

impl<'w> !Sync for RuntimeBuilder<'w>

§

impl<'w> Unpin for RuntimeBuilder<'w>

§

impl<'w> UnsafeUnpin for RuntimeBuilder<'w>

§

impl<'w> !UnwindSafe for RuntimeBuilder<'w>

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.