Safe Haskell | Safe-Inferred |
---|
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
- data Firehose a
- data Subscription a
- newFirehose :: STM (Firehose a)
- writeEvent :: Firehose a -> a -> STM ()
- subscribe :: Int -> Firehose a -> STM (Subscription a)
- unsubscribe :: Subscription a -> STM ()
- readEvent :: Subscription a -> STM (Maybe a)
- getQueue :: Subscription a -> TBMQueue a
Documentation
data Subscription a Source
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.
:: 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
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 aSource
Gets the underlying queue from a subscription.