auralis-task
Scoped async task runtime with cancellation and priority scheduling.
Built on auralis-signal. #![forbid(unsafe_code)]. Single-threaded by design.
Overview
| Type | Role |
|---|---|
TaskScope |
Owns spawned tasks on an executor; with_executor(&ex) for explicit ownership, new() for global |
Executor |
Single-threaded async executor with high/low priority queues |
Priority |
High or Low — high dequeued first each flush cycle |
CallbackHandle |
RAII guard for signal subscriptions (dropped before tasks on scope cancel) |
JoinHandle |
Returned by spawn() — cancel or check completion of a single task |
TaskScope::on_cleanup(f) |
Register a cleanup closure (sugar for CallbackHandle::new) |
TaskScope::watch(sig, f) |
Run f on each signal change |
TaskScope::watch_effect(f) |
Auto-tracking effect — re-runs when any signal read inside f changes |
set_deferred(sig, val) |
Safe Signal::set from Drop contexts |
yield_now() |
Yield control back to the executor once |
schedule_callback(f) |
Run f at the start of the next flush |
timer::sleep(dur) |
Cooperative async delay (requires TimeSource for real-time; degrades to yield_now otherwise) |
TaskScope::is_cancelled() |
Check whether the scope has been dropped and its tasks cancelled |
Quick Start
use Signal;
use ;
// Set up the executor
init_flush_scheduler;
// Structured concurrency
let scope = new;
let sig = new;
let s = sig.clone;
scope.spawn;
drop; // cancels all spawned tasks
Feature Flags
| Feature | Enables |
|---|---|
debug |
dump_task_tree() diagnostic snapshot |
ssr-tokio |
init_scope_store_tokio() for multi-request SSR isolation |
Key Properties
- Scope lifecycle —
TaskScope::droponly cancels on the last reference (Rc::strong_count == 1), matchingMemo::drop. Thecancelledflag is stored outside theRefCellso it is always settable, even during re-entrant drop. - Iterative scope cancellation — BFS collect + leaf-to-root cancel, 200+ nesting levels without stack overflow. Cancel directly looks up tasks by id (no full-table scan).
- Panic-safe cleanup —
CallbackHandle::dropiscatch_unwind-isolated; a panicking cleanup closure does not corrupt scope teardown. - Configurable time budget —
set_global_time_budget(ms), default 8 ms; set tou64::MAXto disable - Panic hook —
set_panic_hook(hook)to observe task failures with task_id and scope_id - Explicit executor ownership —
TaskScope::with_executor(&ex)stores anRcstrong reference; spawn, cancel, and resume all route through the scope's executor without thread-local lookup.TaskScope::new()delegates to the global executor as a convenience. - Instance isolation —
Executor::new_instance()for multi-threaded SSR; slot-based waker routing with generation counters - Cooperative timer —
timer::sleep(dur)works with anyTimeSourceimplementation - Panic-safe callbacks — each deferred signal callback is
catch_unwind-isolated in the executor flush
License
Licensed under either of MIT or Apache 2.0 at your option.