Expand description
An event-loop-per-thread async runtime with JavaScript-style scheduling, built for interactive applications.
Each runite runtime thread owns a single-threaded event loop with
JavaScript-style microtask/macrotask scheduling, backed by a
platform-specific async I/O backend (io_uring on Linux, kqueue on macOS,
IOCP on Windows). Tasks on a thread are !Send and never migrate, so
most runtime state needs no locking; explicit worker threads
provide parallelism and communicate through channels and
ThreadHandles.
Unlike Tokio’s default runtime or async-std, there is no work-stealing
multithreaded scheduler. Continuations and wakeups are queued as microtasks
on the same runtime thread, while timers, I/O callbacks, cross-thread wakes,
and queue_macrotask work run as macrotasks after the microtask queue has
drained.
§Getting started
The usual entry point is the #[runite::main] attribute, which
drives the event loop to completion around your main:
#[runite::main]
async fn main() {
let contents = runite::fs::read_to_string("Cargo.toml").await.unwrap();
println!("{} bytes", contents.len());
}You can also drive the loop yourself. spawn schedules async work
and run runs the current thread until everything queued is complete —
handy for embedding the runtime or writing tests:
use std::rc::Rc;
use std::cell::Cell;
use std::time::Duration;
let total = Rc::new(Cell::new(0u32));
let result = Rc::clone(&total);
runite::spawn(async move {
let (tx, mut rx) = runite::channel::mpsc::channel(8);
runite::spawn(async move {
for value in 1..=3 {
runite::time::sleep(Duration::from_millis(1)).await;
tx.send(value).await.unwrap();
}
});
let mut sum = 0;
while let Some(value) = rx.recv().await {
sum += value;
}
result.set(sum);
});
runite::run();
assert_eq!(total.get(), 6);§Where to look next
mainfor executable entry points (sync orasync fn main)run,queue_macrotask,queue_microtask, andspawnfor driving and feeding the event loopspawn_workerandThreadHandlefor multi-threaded workfs,net,process,time,signal, andstdiofor async runtime serviceschannelformpsc/oneshot/broadcast/watchchannelssyncforMutex,Semaphore,RwLock,Notify, andOnceCelliofor the crate’sAsyncRead/AsyncWrite/Streamtraits andBufReader/BufWritertask::JoinSetfor structured ownership of local child taskstask::spawn_blockingfor offloading blocking work to a thread pool
§Cargo features
hyper— integraterunitesockets with thehyperHTTP library.futures-compat— adapters betweenrunite’s I/O traits and thefutures-ioecosystem (see theio::compatmodule, enabled by this feature).
§Platform support
runite currently targets:
- Linux (io_uring) on
x86_64andaarch64 - macOS
aarch64(kqueue) - Windows (IOCP) on
x86_64
Building for any other target raises a compile error. On Windows, sockets,
files, and child-process pipes are driven by overlapped I/O through one
completion port per runtime thread; runite::fd and runite::net::unix
are Unix-only. See docs/WINDOWS.md in the repository for the backend
design.
§Minimum Linux kernel
The io_uring backend targets Linux 6.1 or newer (the current LTS line), which is what CI and the maintainers test against. It may run on older kernels subject to the feature notes below, but that is not tested.
Hard requirements (no fallback — the runtime will not function without them):
- 5.6 — the base ring:
openat/read/write/fsync/statx/closeand friends, which every file and socket operation builds on. - 5.18 —
IORING_OP_MSG_RING, used to wake one runtime thread from another. A single-threaded runtime can run without it, butspawn_worker-based multithreading (and any cross-threadThreadHandlewake) requires 5.18+.
Soft requirements (a synchronous syscall fallback runs transparently on older kernels, so only native-io_uring performance is affected):
- File truncation (
OpenOptions::truncate,File::set_len) usesIORING_OP_FTRUNCATE(6.9) and falls back toftruncate(2). - The socket lifecycle operations —
socket(5.19),bind/listen(6.11), andconnect/accept/shutdown/send/recv— fall back to their blocking equivalents when the kernel lacks the opcode.
So the recommended 6.1 LTS floor exercises every feature; the only hard lower bounds are 5.6 (single-threaded) and 5.18 (multithreaded).
Re-exports§
pub use stdio::Stderr;pub use stdio::Stdin;pub use stdio::Stdout;pub use stdio::stderr;pub use stdio::stdin;pub use stdio::stdout;pub use task::BlockingJoinHandle;pub use task::JoinError;pub use task::spawn_blocking;
Modules§
- channel
- Async channels for task and thread communication.
- fd
Unix - File-descriptor readiness helpers backed by the runtime driver.
- fs
- Portable async filesystem primitives.
- hyper_
rt hyper - Hyper runtime glue: an executor and a timer backed by runite.
- io
- Asynchronous I/O traits, adapters, and stream utilities.
- net
- Portable async networking primitives.
- os
- OS-specific extensions to runite types, mirroring
std::os. - process
- Async subprocess management.
- signal
- Async signal handling.
- stdio
- Async standard stream helpers.
- sync
- Single-threaded async synchronization primitives.
- task
- Task ownership and blocking-offload primitives.
- time
- Runtime time primitives.
Macros§
- join
- Awaits multiple futures concurrently on the current task.
- select
- Resolves with the handler for the first future that becomes ready.
- try_
join - Awaits multiple
Result-returning futures concurrently on the current task.
Structs§
- Abort
Handle Linux, or Windows, or AArch64 and macOS - Cloneable handle that can abort a queued task without joining it.
- Interval
Handle Linux, or Windows, or AArch64 and macOS - Handle returned by
time::set_interval. - Join
Handle Linux, or Windows, or AArch64 and macOS - Handle returned by
spawn. - Thread
Handle Linux, or Windows, or AArch64 and macOS - A cloneable,
Sendhandle for queueing macrotasks onto a specific runtime thread from any thread. - Timeout
Handle Linux, or Windows, or AArch64 and macOS - Handle returned by
time::set_timeout. - Worker
Handle Linux, or Windows, or AArch64 and macOS - A handle to a worker runtime thread spawned with
spawn_worker. - Yield
Now Linux, or Windows, or AArch64 and macOS - Future returned by
yield_now.
Enums§
- Queue
Error Linux, or Windows, or AArch64 and macOS - Returned by
ThreadHandle::queue_macrotaskwhen the target runtime is shutting down or its cross-thread macrotask queue is full.
Functions§
- block_
on Linux, or Windows, or AArch64 and macOS - Drives the current thread’s event loop until
futurecompletes, then returns its output. - current_
thread_ handle Linux, or Windows, or AArch64 and macOS - Returns a
ThreadHandleto the current runtime thread. - queue_
macrotask Linux, or Windows, or AArch64 and macOS - Queues a one-shot closure to run as a macrotask on the current runtime thread.
- queue_
microtask Linux, or Windows, or AArch64 and macOS - Queues a one-shot closure to run as a microtask on the current runtime thread.
- run
Linux, or Windows, or AArch64 and macOS - Runs the current thread’s event loop until all work is complete.
- run_
ready_ tasks Linux, or Windows, or AArch64 and macOS - Runs only the tasks and microtasks that are ready right now, then returns.
- run_
until_ stalled Linux, or Windows, or AArch64 and macOS - Drives the event loop until it would next block waiting on the I/O driver.
- spawn
Linux, or Windows, or AArch64 and macOS - Spawns
futureonto the current runtime thread and returns aJoinHandle. - spawn_
worker Linux, or Windows, or AArch64 and macOS - Spawns a new OS thread running its own independent runtime event loop.
- yield_
now Linux, or Windows, or AArch64 and macOS - Returns a future that yields back to the runtime scheduler once.