Expand description
A lightweight task execution framework built on top of Tokio’s LocalSet.
§Overview
A Reactor owns a dedicated OS thread running a tokio current_thread
runtime plus a LocalSet. Users register their own typed tasks on
the reactor; each task listens on one or more user-defined channels,
each with its own priority and capacity, and processes incoming
contexts through a user-supplied handler. The dispatch policy is
pluggable via the Scheduler trait; FairPriority (the default) and
StrictPriority are provided.
use hyperfile_reactor::{Capacity, Reactor, Task, TaskBuilder};
struct MyTask;
impl Task<u64> for MyTask {
async fn handle(&mut self, ctx: u64) {
println!("got {ctx}");
}
}
let reactor = Reactor::<u64, MyTask>::new_current().unwrap();
let mut builder = TaskBuilder::<u64>::new();
let high = builder.add_channel(0, Capacity::Bounded(64)); // backpressured
let low = builder.add_channel(9, Capacity::Unbounded);
let handler = reactor.spawn(MyTask, builder).expect("spawn");
handler.send(high, 1).unwrap();
handler.send(low, 2).unwrap();Structs§
- Channel
- An opaque token identifying one channel registered on a task.
- Fair
Priority - Strict priority with anti-starvation: after
budgetconsecutive items from the top-priority band, serve one item from the lowest non-empty band if any is waiting. - Reactor
- Owns the background thread running the tokio runtime +
LocalSet. - Send
Error - Returned when a send fails because the task has stopped.
- Spawn
Error - Returned when spawning a task fails because the reactor thread is gone.
- Strict
Priority - Strict priority: always serve the highest-priority non-empty channel. Lower-priority channels may starve if higher ones never drain.
- Task
Builder - Declares the set of channels a task will receive on.
- Task
Handler - Producer-side handle. Cheap to clone; can be shared across threads.
Enums§
- Capacity
- Channel capacity policy.
- DynReceiver
- Internal unified receiver used by
Schedulerimplementations. - TrySend
Error - Returned from non-blocking send paths: either the bounded channel is full or the task has stopped.