nqe-0.6.4: Concurrency library in the style of Erlang/OTP
CopyrightNo rights reserved
LicenseUNLICENSE
Maintainerxenog@protonmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.NQE.Publisher

Description

A publisher is a process that forwards messages to subscribers. NQE publishers are simple, and do not implement filtering directly, although that can be done on the STM Listen actions that forward messages to subscribers.

If a subscriber has been added to a publisher using the subscribe function, it needs to be removed later using unsubscribe when it is no longer needed, or the publisher will continue calling its Listen action in the future, likely causing memory leaks.

Synopsis

Documentation

data Subscriber msg Source #

Handle of a subscriber to a process. Should be kept in order to unsubscribe.

Instances

Instances details
Eq (Subscriber msg) Source # 
Instance details

Defined in Control.Concurrent.NQE.Publisher

Methods

(==) :: Subscriber msg -> Subscriber msg -> Bool #

(/=) :: Subscriber msg -> Subscriber msg -> Bool #

Hashable (Subscriber msg) Source # 
Instance details

Defined in Control.Concurrent.NQE.Publisher

Methods

hashWithSalt :: Int -> Subscriber msg -> Int #

hash :: Subscriber msg -> Int #

data PublisherMessage msg Source #

Messages that a publisher will take.

Constructors

Subscribe !(Listen msg) !(Listen (Subscriber msg)) 
Unsubscribe !(Subscriber msg) 
Event msg 

type Publisher msg = Process (PublisherMessage msg) Source #

Alias for a publisher process.

withSubscription :: MonadUnliftIO m => Publisher msg -> (Inbox msg -> m a) -> m a Source #

Create a mailbox, subscribe it to a publisher and pass it to the supplied function . End subscription when function returns.

subscribe :: MonadIO m => Publisher msg -> Listen msg -> m (Subscriber msg) Source #

Listen to events from a publisher.

unsubscribe :: MonadIO m => Publisher msg -> Subscriber msg -> m () Source #

Stop listening to events from a publisher. Must provide Subscriber that was returned from corresponding subscribe action.

withPublisher :: MonadUnliftIO m => (Publisher msg -> m a) -> m a Source #

Start a publisher in the background and pass it to a function. The publisher will be stopped when the function function returns.

publisher :: MonadUnliftIO m => m (Publisher msg) Source #

Start a publisher in the background.

publisherProcess :: MonadUnliftIO m => Inbox (PublisherMessage msg) -> m () Source #

Start a publisher in the current thread.

publish :: MonadIO m => msg -> Publisher msg -> m () Source #

publishSTM :: msg -> Publisher msg -> STM () Source #