Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Producer p r = Producer {
- producerQueueRead :: STM (Msg p r)
- producerThread :: ThreadId
- data ProducerCancelled = ProducerCancelled
- data Msg p r
- = Payload p
- | Exception SomeException
- | Close r
- forkProducer :: forall m p r. (MonadIO m, MonadUnliftIO m) => ((p -> m ()) -> m r) -> m (Producer p r)
- cancel :: MonadIO m => Producer p r -> m ()
- withProducer :: (MonadIO m, MonadUnliftIO m) => ((p -> m ()) -> m r) -> (Producer p r -> m a) -> m a
- listen :: MonadIO m => Producer p r -> (p -> m a) -> (r -> m a) -> STM (m a)
- joinSTM :: MonadIO m => STM (m a) -> m a
- data Syncing a
- = Syncable a
- | Syncer (Maybe SomeException -> STM ())
- withSync :: (MonadIO m, MonadUnliftIO m, Traversable t) => t (Syncing a) -> (t (Maybe a) -> m b) -> m b
- withBoundedDelayBatchProducer :: (MonadIO m, MonadUnliftIO m, KatipContext m) => Int -> Int -> Producer p r -> (Producer [p] r -> m a) -> m a
- syncer :: MonadIO m => (Syncing a -> m ()) -> m ()
Documentation
A thread producing zero or more payloads and a final value. Handles exception propagation.
Producer | |
|
data ProducerCancelled Source #
Instances
Exception ProducerCancelled Source # | |
Defined in Hercules.Agent.Producer | |
Show ProducerCancelled Source # | |
Defined in Hercules.Agent.Producer showsPrec :: Int -> ProducerCancelled -> ShowS # show :: ProducerCancelled -> String # showList :: [ProducerCancelled] -> ShowS # |
Payload p | One of possibly many payloads from the producer |
Exception SomeException | The producer stopped due to an exception |
Close r | The producer was done and produced a final value |
forkProducer :: forall m p r. (MonadIO m, MonadUnliftIO m) => ((p -> m ()) -> m r) -> m (Producer p r) Source #
forkProducer f
produces a computation that forks a thread for f
, which
receives a function for returning payloads p
.
f
may produce a final result value r
when it is done.
cancel :: MonadIO m => Producer p r -> m () Source #
Throws ProducerCancelled
as an async exception to the producer thread.
Blocks until exception is raised. See throwTo
.
withProducer :: (MonadIO m, MonadUnliftIO m) => ((p -> m ()) -> m r) -> (Producer p r -> m a) -> m a Source #
Perform an computation while withProducer
takes care of forking and cleaning up.
withProducer (write -> write "a" >> write "b") $ producer -> consume producer
withSync :: (MonadIO m, MonadUnliftIO m, Traversable t) => t (Syncing a) -> (t (Maybe a) -> m b) -> m b Source #
Sends sync notifications after the whole computation succeeds (or fails) Note: not exception safe in the presence of pure exceptions.
withBoundedDelayBatchProducer Source #
:: (MonadIO m, MonadUnliftIO m, KatipContext m) | |
=> Int | Max time before flushing in microseconds |
-> Int | Max number of items in batch |
-> Producer p r | |
-> (Producer [p] r -> m a) | |
-> m a |