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
impl Runtime
Sourcepub fn new(world: &mut World) -> Self
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.
Sourcepub fn builder(world: &mut World) -> RuntimeBuilder<'_>
pub fn builder(world: &mut World) -> RuntimeBuilder<'_>
Create a runtime via the builder pattern.
Sourcepub fn shutdown_handle(&self) -> ShutdownHandle
pub fn shutdown_handle(&self) -> ShutdownHandle
Returns a ShutdownHandle for triggering or observing shutdown.
Sourcepub fn install_signal_handlers(&self)
pub fn install_signal_handlers(&self)
Install signal handlers for SIGTERM and SIGINT.
Sourcepub fn task_count(&self) -> usize
pub fn task_count(&self) -> usize
Number of live spawned tasks.
Source§impl Runtime
impl Runtime
Sourcepub fn block_on<F>(&mut self, future: F) -> F::Outputwhere
F: Future + 'static,
pub fn block_on<F>(&mut self, future: F) -> F::Outputwhere
F: Future + 'static,
Drive the root future to completion. CPU-friendly.
Parks the thread when no work is available.
Sourcepub fn block_on_busy<F>(&mut self, future: F) -> F::Outputwhere
F: Future + 'static,
pub fn block_on_busy<F>(&mut self, future: F) -> F::Outputwhere
F: Future + 'static,
Drive the root future to completion. Busy-wait.
Never parks. Minimum wake latency at 100% CPU.
Auto Trait Implementations§
impl !Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl !Send for Runtime
impl !Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
impl !UnwindSafe for Runtime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more