stm-firehose-0.3.0: Conduits and STM operations for fire hoses.

Safe HaskellSafe
LanguageHaskell2010

Control.Concurrent.STM.Firehose

Description

A subscription based messaging system, with non-blocking bounded write.

fh <- atomically newFirehose
-- the following line will not block, even though nobody subscribed
atomically (mapM_ (writeEvent fh) [1..100])
-- let's subscribe a single client
sub <- atomically (subscribe 10 fh)
forkIO (forever (atomically (readEvent sub) >>= print))
atomically $ writeEvent fh 1

Synopsis

Documentation

newFirehose :: STM (Firehose a) Source

Creates a new Firehose item.

writeEvent :: Firehose a -> a -> STM () Source

Sends a piece of data in the fire hose.

subscribe Source

Arguments

:: Int

Number of elements buffered. If set too high, it will increase memory usage. If set too low, activity spikes will result in message loss.

-> Firehose a 
-> STM (Subscription a) 

Get a subscription from the fire hose, that will be used to read events.

unsubscribe :: Subscription a -> STM () Source

Unsubscribe from the fire hose. Subsequent calls to readEvent will return Nothing. This runs in O(n), where n is the current number of subscriptions. Please contact the maintainer if you need better performance.

readEvent :: Subscription a -> STM (Maybe a) Source

Read an event from a Subscription. This will return Nothing if the firehose is shut, or the subscription removed.

getQueue :: Subscription a -> TBMQueue a Source

Gets the underlying queue from a subscription.