broadcast-chan-0.1.1: Broadcast channel type that avoids 0 reader space leaks.

Copyright(C) 2014 Merijn Verstraaten
LicenseBSD-style (see the file LICENSE)
MaintainerMerijn Verstraaten <merijn@inconsistent.nl>
Stabilityexperimental
Portabilityhaha
Safe HaskellSafe
LanguageHaskell2010

Control.Concurrent.BroadcastChan

Description

A variation of Control.Concurrent.Chan from base, which allows to the easy creation of broadcast channels without the space-leaks that may arise from using dupChan.

The Chan type from Control.Concurrent.Chan consists of both a read and write end. This presents a problem when one wants to have a broadcast channel that, at times, has zero listeners. To write to a Chan there must always be a read end and this read end will hold ALL messages alive until read.

The simple solution applied in this module is to separate read and write ends. As a result, any messages written to the write end can be immediately garbage collected if there are no active read ends, avoding space leaks.

Synopsis

Documentation

data BroadcastChan d a #

The abstract type representing the read or write end of a BroadcastChan.

Instances

Eq (BroadcastChan d a) # 

Methods

(==) :: BroadcastChan d a -> BroadcastChan d a -> Bool #

(/=) :: BroadcastChan d a -> BroadcastChan d a -> Bool #

type In = In #

Alias for the In type from the Direction kind, allows users to write the 'BroadcastChan In a' type without enabling DataKinds.

type Out = Out #

Alias for the Out type from the Direction kind, allows users to write the 'BroadcastChan Out a' type without enabling DataKinds.

newBroadcastChan :: IO (BroadcastChan In a) #

Creates a new BroadcastChan write end.

writeBChan :: BroadcastChan In a -> a -> IO () #

Write a value to write end of a BroadcastChan. Any messages written while there are no live read ends can be immediately garbage collected, thus avoiding space leaks.

readBChan :: BroadcastChan Out a -> IO a #

Read the next value from the read end of a BroadcastChan.

newBChanListener :: BroadcastChan In a -> IO (BroadcastChan Out a) #

Create a new read end for a BroadcastChan. Will receive all messages written to the channel's write end after the read end's creation.