Skip to main content

Crate hyperfile_reactor

Crate hyperfile_reactor 

Source
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.
FairPriority
Strict priority with anti-starvation: after budget consecutive 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.
SendError
Returned when a send fails because the task has stopped.
SpawnError
Returned when spawning a task fails because the reactor thread is gone.
StrictPriority
Strict priority: always serve the highest-priority non-empty channel. Lower-priority channels may starve if higher ones never drain.
TaskBuilder
Declares the set of channels a task will receive on.
TaskHandler
Producer-side handle. Cheap to clone; can be shared across threads.

Enums§

Capacity
Channel capacity policy.
DynReceiver
Internal unified receiver used by Scheduler implementations.
TrySendError
Returned from non-blocking send paths: either the bounded channel is full or the task has stopped.

Traits§

Scheduler
Pluggable dispatch policy.
Task
Business-logic trait. Implemented by users for each task type.