nqe-0.5.0: Concurrency library in the style of Erlang/OTP

Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.NQE.PubSub

Synopsis

Documentation

type Publisher msg = Inbox (ControlMsg msg) Source #

Wrapper for a Mailbox that can receive ControlMsg.

publisher :: MonadIO m => Publisher event -> STM event -> m () Source #

Start a publisher that will receive events from an STM action, and subscription requests from a Publisher mailbox. Events will be forwarded atomically to all subscribers. Full mailboxes will not receive events.

subscribe :: MonadIO m => Publisher event -> Inbox event -> m () Source #

Subscribe an Inbox to a Publisher generating events.

unsubscribe :: MonadIO m => Publisher event -> Inbox event -> m () Source #

Unsubscribe an Inbox from a Publisher events.

withPubSub Source #

Arguments

:: (MonadUnliftIO m, Mailbox mbox event) 
=> Publisher event 
-> m (mbox event)

mailbox creator for this subscription

-> (Inbox event -> m a)

unsubscribe when this action ends

-> m a 

Subscribe an Inbox to events from a Publisher. Unsubscribe when action finishes. Pass a mailbox constructor.