nuclei 0.5.2

Proactive IO & runtime system
Documentation
//! nuclei's own runtime: thread-per-core shards that run tasks, a blocking
//! pool, and the functions that place work on them.
//!
//! A [`Runtime`] runs one shard per worker thread. A shard owns its run
//! queue, its timers and its poller, and a task stays on the shard it was
//! placed on: [`spawn`] keeps it near the spawning thread's other tasks
//! within a margin of load (see [`Builder::local_spawn_margin`]),
//! [`spawn_local`] keeps it on the calling thread. [`block_on`] runs a
//! future on the calling thread and nests: called from a task, it keeps the
//! shard running its other tasks until the future completes.
//!
//! [`RuntimeHandle::spawn_on_worker`], [`RuntimeHandle::on_each_worker`] and
//! [`task::Builder::worker`](crate::task::Builder::worker) place a task on a
//! worker the caller names, where it stays; [`shard_local!`](crate::shard_local)
//! keeps a [`ShardLocal`](crate::runtime::ShardLocal) value per worker, which moves with the worker's
//! shard when a handoff gives the shard to another thread.
//!
//! The free functions use the runtime the calling thread is inside, or the
//! process default runtime, which starts on first use with no configuration
//! (one worker per core). [`Builder`] sets everything else, and
//! [`Runtime::stats`] reads one runtime's counters.
//!
//! ```
//! use nuclei::runtime::{Runtime, spawn};
//!
//! let runtime = Runtime::builder().worker_threads(2).build().unwrap();
//! let sum = runtime.block_on(async {
//!     let tasks: Vec<_> = (0..4u64).map(|n| spawn(async move { n * n })).collect();
//!     let mut sum = 0;
//!     for task in tasks {
//!         sum += task.await;
//!     }
//!     sum
//! });
//! assert_eq!(sum, 14);
//! ```

pub use crate::rt::runtime::{
    Builder, EnterGuard, RngSeed, Runtime, RuntimeHandle, RuntimeId, TaskMeta, TryCurrentError,
    UnhandledPanic, block_on, spawn, spawn_blocking, spawn_local, worker_index,
};
pub use crate::rt::task::{FallibleTask, Task};
pub use crate::shard_local::{ShardAccessError, ShardLocal};