Antiox – Tokio-like async primitives for TypeScript

https://lobste.rs/rss Hits: 10
Summary

Pre-release: This library is used in production but the API is subject to change. Eliminate async concurrency bugs: Composing Promise.all, AbortController, and setTimeout by hand creates exponential edge cases around cancellation, ordering, and teardown. Tokio solves this in Rust with structured concurrency primitives. Antiox brings the same primitives to TypeScript. Async primitives: Channels, streams, select, tasks, and more. Everything you need for structured concurrency and backpressure. Lightweight: No custom DSL, no wrapper types, no unnecessary allocations, and no dependencies. Every module is tree-shakeable and tiny enough to ship as a transitive dependency. Rust-shaped: Same structure, naming, and control flow as Tokio. LLMs know Rust/Tokio well, and this translates directly to Antiox. And let's be honest, you probably wish you were writing Rust right now instead. But the world runs on JS. The most common pattern in antiox is pairing a channel with a task to build an actor-like system. All communication goes through channels, giving you structured concurrency, backpressure, and clean shutdown without callbacks, event emitters, or custom DSLs. import { channel } from "antiox/sync/mpsc"; import { oneshot, OneshotSender } from "antiox/sync/oneshot"; import { unreachable } from "antiox/panic"; import { spawn } from "antiox/task"; type Msg = | { type: "increment"; amount: number } | { type: "get"; resTx: OneshotSender<number> }; const [tx, rx] = channel<Msg>(32); spawn(async () => { let count = 0; for await (const msg of rx) { switch (msg.type) { case "increment": count += msg.amount; break; case "get": msg.resTx.send(count); break; default: // `unreachable(x: never)` provides compile-time exhaustiveness checking for switch statements unreachable(msg); } } }); // Fire-and-forget await tx.send({ type: "increment", amount: 5 }); // Request-response via oneshot channel const [resTx, resRx] = oneshot<number>(); await tx.send({ type: "get", resTx }); const value = aw...

First seen: 2026-03-27 23:32

Last seen: 2026-03-28 08:37