How Asupersync enforces cancel-correctness, structured concurrency, and deterministic testing.
Asupersync's runtime is built on three pillars: Regions for structure, the Cancel Protocol for cleanup, and the Lab for testing.
Every task lives inside a Region. Regions form a tree. When a parent Region closes, all children are cancelled — automatically.
01// Regions scope task lifetimes02Region::open(cx, "server", |cx| {03 // Child tasks are bound to this Region04 cx.spawn("worker-1", handle_requests());05 cx.spawn("worker-2", process_queue());06 07 // When this Region closes, workers are cancelled08 // via the cancel protocol (not silently dropped)09 cx.shutdown_signal().;10}).Unlike Tokio's tokio::spawn which creates globally-scoped tasks, Asupersync tasks are always scoped to a Region. This eliminates orphaned futures — if you can't see the task, it can't outlive you.
Three phases ensure resources are always cleaned up, even during cancellation.
Cancel signal sent. Task sees CancelRequested on its Cx. Can begin graceful shutdown.
Task gets budgeted time to finish in-flight work. Flush buffers, close connections, release locks.
Registered finalizers run in LIFO order. Like defer in Go, but integrated with the cancel protocol.
From formal proofs to published crate.
Core Runtime & Region Model
Designed the Region tree model with parent-child lifetime scoping
Implemented the three-phase cancel protocol (Request → Drain → Finalize)
Built the Cx capability context with spawn/IO/timer gates
Formal proofs for cancel-safety and region closure guarantees
Linear Obligations & Permits
Designed the Permit/Lease linear type system
Implemented compile-time must-use enforcement
Built the three consumption paths: Send, Complete, Abort
Added Spork (spawn + fork) for structured task hierarchies
Three-Lane Scheduler
Implemented Cancel/Timed/Ready lane architecture
Built priority inversion prevention for cancel propagation
Designed quiescence detection for region closure
Benchmarked against Tokio's work-stealing scheduler
Lab Runtime & DPOR
Built deterministic executor with seed-controlled ordering
Implemented Dynamic Partial Order Reduction for systematic testing
Added replay capability for reproducing concurrency bugs
Integrated with cargo test for seamless developer experience
Built-in Protocols & Ecosystem
Implemented cancel-correct TCP, HTTP/1.1, and WebSocket protocols
Built cancel-aware channels, mutexes, and semaphores
Added supervisor trees with restart policies
Published to crates.io with comprehensive documentation