amphp/amp is a PHP library providing fundamental asynchronous concurrency primitives: Futures (promises) and Cancellations. It is built on top of the Revolt event loop and leverages PHP 8.1 fibers for cooperative multitasking, eliminating the need for generator-based coroutines or callback-heavy APIs. The library offers a Future class with methods like map(), catch(), finally(), and await() for composing asynchronous operations, along with combinators (await, awaitFirst, awaitAny, awaitAnyN, awaitAll) for concurrent execution. Cancellation is handled via a clean interface with implementations for timeouts (TimeoutCancellation), OS signals (SignalCancellation), manual cancellation (DeferredCancellation), and composition (CompositeCancellation). Utility functions include async() for spawning fibers, delay() for non-blocking sleep, trapSignal() for awaiting signals, and weakClosure() to prevent circular references in closures. The architecture is modular, with internal state management separated from public APIs, and strict typing throughout. External dependency is limited to revolt/event-loop for the event loop and suspension API.
Axios is a promise-based HTTP client for both browser and Node.js environments. It provides a rich feature set including request/response interceptors, automatic JSON serialization, cancellation via AbortController or legacy CancelToken, progress tracking, CSRF protection, and support for multiple adapters (XHR, HTTP, Fetch). The library is designed with a modular architecture: core classes (Axios, AxiosError, AxiosHeaders, InterceptorManager) handle request lifecycle and configuration merging, while platform-specific adapters handle actual network I/O. A comprehensive set of helper utilities (composeSignals, progressEventReducer, sanitizeHeaderValue, etc.) implement reusable patterns for signal composition, throttled progress events, header injection prevention, and more. The codebase is extensively tested across runtimes (Node, browser, Bun, Deno) and includes security hardening against prototype pollution, SSRF, and CRLF injection. While primarily a library for other applications, its architecture demonstrates strong separation of concerns and many components are independently reusable.
Gears is an experimental asynchronous programming library for Scala 3 that enables direct-style async programming with structured concurrency. It provides Futures for concurrent computations, Channels for communication between computations, and an Async context for managing execution. The library works across JVM (with virtual threads), Scala Native, and Scala.js (with Wasm support), implementing structured concurrency principles with automatic cancellation propagation. The architecture features a shared core with platform-specific implementations, using delimited continuations or fibers for suspension/resume operations.
The speculation library provides cancellable promises as a drop-in replacement for standard JavaScript promises. The core functionality is implemented in src/index.js, where the speculation function wraps the native Promise constructor to accept a cancellation promise. When the cancellation promise resolves, it triggers a cleanup handler before rejecting the speculation. The library also includes a wait utility (src/wait.js) that uses speculation to create cancellable delays. The implementation is self-contained, relies only on native Promises, and follows the Promise/A+ specification. Despite its small size, the solution demonstrates careful handling of edge cases like settlement before cancellation and error propagation in cancellation handlers.