Skip to main content

Module executor

Module executor 

Source
Expand description

Async executor: single-threaded (default) and multi-threaded (opt-in).

§Single-threaded run loop (default)

block_on(future)
  └─ Executor::run_loop
       ├─ LocalQueue  (LIFO ring, 256 slots)
       ├─ GlobalQueue (Mutex<VecDeque> — waker injection)
       └─ Reactor     (kqueue/epoll — parks when no work is ready)

§Multi-threaded run loop (opt-in via RuntimeBuilder::worker_threads(n))

block_on_multi(future, n_workers)
  ├─ worker 0 (main thread) — polls root future + runs tasks
  ├─ worker 1..N-1 (spawned threads) — steal and run tasks
  └─ GlobalQueue + WorkStealingPool shared across all workers

Single-threaded mode is the default. Multi-thread is explicitly opt-in.

Modules§

scheduler
Per-core task queues: LocalQueue (ring buffer) + GlobalQueue (mutex deque).
task
Task lifecycle types: TaskHeader, Task, JoinHandle.
task_local
Task-local storage for async contexts.
waker
Custom RawWakerVTable implementation.
work_stealing
Opt-in work-stealing layer.
worker
Per-worker state for the multi-threaded executor.

Structs§

Executor
Per-thread async executor (single-threaded mode).

Functions§

block_on
Drive future to completion on the current thread, returning its output.
block_on_multi
Drive future to completion using num_workers OS threads.
block_on_with_spawn
Drive future to completion with spawn() available in the async context.
spawn
Spawn a future onto the current thread’s executor.