broadcast-chan: Closable, fair, single-wakeup channel type that avoids 0 reader space leaks.
WARNING: While the code in this library should be fairly stable and production, the API is something I'm still working on. API changes will follow the PVP, but expect breaking API changes in future versions!
A closable, fair, single-wakeup channel that avoids the 0 reader space leak
that Control.Concurrent.Chan from base suffers from.
The Chan type from Control.Concurrent.Chan consists of both a read
and write end combined into a single value. This means there is always at
least 1 read end for a Chan, which keeps any values written to it alive.
This is a problem for applications/libraries that want to have a channel
that can have zero listeners.
Suppose we have an library that produces events and we want to let users
register to receive events. If we use a channel and write all events to it,
we would like to drop and garbage collect any events that take place when
there are 0 listeners. The always present read end of Chan from base
makes this impossible. We end up with a Chan that forever accumulates
more and more events that will never get removed, resulting in a memory
leak.
BroadcastChan splits channels into separate read and write ends. Any
message written to a a channel with no existing read end is immediately
dropped so it can be garbage collected. Once a read end is created, all
messages written to the channel will be accessible to that read end.
Once all read ends for a channel have disappeared and been garbage collected, the channel will return to dropping messages as soon as they are written.
Why should I use BroadcastChan over Control.Concurrent.Chan?
BroadcastChanis closable,BroadcastChanhas no 0 reader space leak,BroadcastChanhas comparable or better performance.
Why should I use BroadcastChan over various (closable) STM channels?
BroadcastChanis single-wakeup,BroadcastChanis fair,BroadcastChanperforms better under contention.
[Skip to Readme]
library broadcast-chan
library broadcast-chan:test
library broadcast-chan:pipes
library broadcast-chan:conduit
Flags
Manual Flags
| Name | Description | Default |
|---|---|---|
| sync | Benchmarks synchronisation primitives used in main benchmark. | Disabled |
| threaded | Run benchmarks with threaded backend. | Enabled |
Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info
Downloads
- broadcast-chan-0.3.0.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
| Versions [RSS] | 0.1.0, 0.1.1, 0.2.0, 0.2.0.1, 0.2.0.2, 0.2.1, 0.2.1.1, 0.2.1.2, 0.3.0 |
|---|---|
| Change log | CHANGELOG.md |
| Dependencies | async (>=2.1 && <2.3), base (>=4.8 && <4.22), broadcast-chan, clock (>=0.7 && <0.9), containers (>=0.4 && <0.9), optparse-applicative (>=0.12 && <0.19), paramtree (>=0.1.1 && <0.2), pipes-safe (>=2.3.1 && <2.4), resourcet (>=1.1 && <1.4), stm (>=2.4 && <2.6), tagged (>=0.8 && <0.9), tasty (>=0.11 && <1.6), tasty-golden (>=2.0 && <2.4), tasty-hunit (>=0.9 && <0.11), temporary (>=1.2 && <1.4), text (>=1.0 && <1.3 || >=2.0 && <2.2), transformers (>=0.2 && <0.7), unliftio-core (>=0.1.1 && <0.3) [details] |
| Tested with | ghc ==8.0.2, ghc ==8.2.2, ghc ==8.4.4, ghc ==8.6.5, ghc ==8.8.4, ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.7, ghc ==9.4.8, ghc ==9.6.6, ghc ==9.8.4, ghc ==9.10.1, ghc ==9.12.1 |
| License | BSD-3-Clause |
| Copyright | Copyright © 2014-2025 Merijn Verstraaten |
| Author | Merijn Verstraaten |
| Maintainer | Merijn Verstraaten <merijn@inconsistent.nl> |
| Category | System |
| Home page | https://github.com/merijn/broadcast-chan |
| Bug tracker | https://github.com/merijn/broadcast-chan/issues |
| Source repo | head: git clone ssh://github.com:merijn/broadcast-chan.git |
| Uploaded | by MerijnVerstraaten at 2025-03-16T18:00:54Z |
| Distributions | Arch:0.2.1.2, Debian:0.2.1.1, NixOS:0.3.0 |
| Reverse Dependencies | 7 direct, 0 indirect [details] |
| Downloads | 7132 total (23 in the last 30 days) |
| Rating | (no votes yet) [estimated by Bayesian average] |
| Your Rating | |
| Status | Docs uploaded by user Build status unknown [no reports yet] |