Copyright | No rights reserved |
---|---|
License | UNLICENSE |
Maintainer | xenog@protonmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
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
- data Subscriber msg
- data PublisherMessage msg
- = Subscribe !(Listen msg) !(Listen (Subscriber msg))
- | Unsubscribe !(Subscriber msg)
- | Event msg
- type Publisher msg = Process (PublisherMessage msg)
- withSubscription :: MonadUnliftIO m => Publisher msg -> (Inbox msg -> m a) -> m a
- subscribe :: MonadIO m => Publisher msg -> Listen msg -> m (Subscriber msg)
- unsubscribe :: MonadIO m => Publisher msg -> Subscriber msg -> m ()
- withPublisher :: MonadUnliftIO m => (Publisher msg -> m a) -> m a
- publisher :: MonadUnliftIO m => m (Publisher msg)
- publisherProcess :: MonadUnliftIO m => Inbox (PublisherMessage msg) -> m ()
Documentation
data Subscriber msg Source #
Handle of a subscriber to a process. Should be kept in order to unsubscribe.
Instances
Eq (Subscriber msg) Source # | |
Defined in Control.Concurrent.NQE.Publisher (==) :: Subscriber msg -> Subscriber msg -> Bool # (/=) :: Subscriber msg -> Subscriber msg -> Bool # | |
Hashable (Subscriber msg) Source # | |
Defined in Control.Concurrent.NQE.Publisher hashWithSalt :: Int -> Subscriber msg -> Int # hash :: Subscriber msg -> Int # |
data PublisherMessage msg Source #
Messages that a publisher will take.
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.