$ show lampepfl/gears
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 LLM identified 3 files worth highlighting for reuse:
Implements the listener pattern for async sources with sophisticated locking mechanisms to handle concurrent access safely. Includes ListenerLock interface, NumberedLock for unique lock identification, and ForwardingListener for source transformation. This component could be extracted for use in any async system needing safe listener management.
Provides multiple channel implementations (SyncChannel, BufferedChannel, UnboundedChannel) and a ChannelMultiplexer for broadcasting messages. Features efficient reader/writer matching via CellBuf, proper blocking/non-blocking semantics, and clean separation of concerns. This communication layer could be reused in any concurrent system.
Implements cancellation groups that track collections of cancellable objects and allow cancelling all members simultaneously. Central to the library's structured concurrency model, this clean implementation handles member tracking, group cancellation, and completion waiting. The pattern is broadly applicable to any resource management scenario.