go_channels library
Go-style concurrency for Dart: typed Channels, a faithful select, and structured task scopes with cancellation.
Classes
- CancelToken
- A cooperative cancellation signal.
-
Channel<
T> -
A CSP-style channel that carries values of type
Tbetween asynchronous tasks, modelled on Go's channels. -
SelectCases<
R> - Collects the branches of a select. Register a receive with onReceive, a send with onSend, a non-blocking fallback with onDefault, and a deadline with onTimeout.
- TaskScope
- A structured-concurrency scope: a group of tasks that all finish before the scope returns, and where one failure cancels the rest (fail-fast).
Functions
-
select<
R> (void build(SelectCases< R> cases)) → Future<R> -
Waits on several channel operations at once and runs exactly one, modelled
on Go's
select. Register branches with the SelectCases builder: -
waitAll<
T> (Iterable< FutureOr< tasks, {CancelToken? parent}) → Future<T> Function(CancelToken token)>List< T> > -
Runs
tasksconcurrently under one scope and returns their results in order. Fails fast: the first error cancels the rest and is rethrown. -
withTaskScope<
R> (FutureOr< R> body(TaskScope scope), {CancelToken? parent}) → Future<R> -
Runs
bodyin a fresh TaskScope and returns its result once every task spawned inside has finished. -
withTimeout<
T> (Duration duration, FutureOr< T> task(CancelToken token), {CancelToken? parent}) → Future<T> -
Runs
taskwith a token that is cancelled afterduration.
Exceptions / Errors
- CancelledException
- Thrown by CancelToken.throwIfCancelled when a token has been cancelled.
- ChannelClosedError
- Thrown by Channel.receive when the channel is closed and no values are left to drain. Use Channel.receiveOr or Channel.stream if you would rather observe closure without an exception.