Copyright | (C) 2014-2018 Merijn Verstraaten |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Merijn Verstraaten <merijn@inconsistent.nl> |
Stability | experimental |
Portability | haha |
Safe Haskell | Safe |
Language | Haskell2010 |
This module is identical to BroadcastChan.Throw, but replaces
BroadcastChan.Throw.
parMapM_
with parMapM
and
parMapM_
which create a parallel processing conduit and sink,
respectively.
Synopsis
- data Action
- data Handler (m :: * -> *) a
- = Simple Action
- | Handle (a -> SomeException -> m Action)
- parMapM :: (MonadResource m, MonadUnliftIO m) => Handler m a -> Int -> (a -> m b) -> ConduitM a b m ()
- parMapM_ :: (MonadResource m, MonadUnliftIO m) => Handler m a -> Int -> (a -> m ()) -> ConduitM a Void m ()
- data BroadcastChan (d :: Direction) a
- data Direction
- type In = In
- type Out = Out
- newBroadcastChan :: MonadIO m => m (BroadcastChan In a)
- newBChanListener :: MonadIO m => BroadcastChan In a -> m (BroadcastChan Out a)
- closeBChan :: MonadIO m => BroadcastChan In a -> m Bool
- isClosedBChan :: MonadIO m => BroadcastChan In a -> m Bool
- getBChanContents :: BroadcastChan In a -> IO [a]
- foldBChan :: MonadIO m => (x -> a -> x) -> x -> (x -> b) -> BroadcastChan In a -> m (m b)
- foldBChanM :: MonadIO m => (x -> a -> m x) -> m x -> (x -> m b) -> BroadcastChan In a -> m (m b)
Documentation
Action to take when an exception occurs while processing an element.
:: (MonadResource m, MonadUnliftIO m) | |
=> Handler m a | Exception handler |
-> Int | Number of parallel threads to use |
-> (a -> m b) | Function to run in parallel |
-> ConduitM a b m () |
Create a conduit that processes inputs in parallel.
This function does *NOT* guarantee that input elements are processed or output in a deterministic order!
:: (MonadResource m, MonadUnliftIO m) | |
=> Handler m a | Exception handler |
-> Int | Number of parallel threads to use |
-> (a -> m ()) | Function to run in parallel |
-> ConduitM a Void m () |
Create a conduit sink that consumes inputs in parallel.
This function does *NOT* guarantee that input elements are processed or output in a deterministic order!
Re-exports from BroadcastChan
Datatypes
data BroadcastChan (d :: Direction) a #
The abstract type representing the read or write end of a BroadcastChan
.
Instances
Eq (BroadcastChan d a) | |
(==) :: BroadcastChan d a -> BroadcastChan d a -> Bool # (/=) :: BroadcastChan d a -> BroadcastChan d a -> Bool # |
Used with DataKinds as phantom type indicating whether a BroadcastChan
value is a read or write end.
In | Indicates a write |
Out | Indicates a read |
Alias for the In
type from the Direction
kind, allows users to write
the
type without enabling BroadcastChan
In
aDataKinds
.
Alias for the Out
type from the Direction
kind, allows users to write
the
type without enabling BroadcastChan
Out
aDataKinds
.
Construction
newBroadcastChan :: MonadIO m => m (BroadcastChan In a) #
Creates a new BroadcastChan
write end.
newBChanListener :: MonadIO m => BroadcastChan In a -> m (BroadcastChan Out a) #
Create a new read end for a BroadcastChan
. Will receive all messages
written to the channel after this read end is created.
Basic Operations
closeBChan :: MonadIO m => BroadcastChan In a -> m Bool #
Close a BroadcastChan
, disallowing further writes. Returns True
if the
BroadcastChan
was closed. Returns False
if the BroadcastChan
was
already closed.
isClosedBChan :: MonadIO m => BroadcastChan In a -> m Bool #
Check whether a BroadcastChan
is closed. True
means it's closed,
False
means it's writable. However:
Beware of TOC-TOU races: It is possible for a BroadcastChan
to be
closed by another thread. If multiple threads use the same BroadcastChan
a
closeBChan
from another thread might result in the channel being closed
right after isClosedBChan
returns.
Utility functions
getBChanContents :: BroadcastChan In a -> IO [a] #
Return a lazy list representing everything written to the supplied
BroadcastChan
after this IO action returns. Similar to
getChanContents
.
Uses unsafeInterleaveIO
to defer the IO operations.
Foldl combinators
Combinators for use with Tekmo's foldl
package.
foldBChan :: MonadIO m => (x -> a -> x) -> x -> (x -> b) -> BroadcastChan In a -> m (m b) #
Strict fold of the BroadcastChan'
s elements. Can be used with
Control.Foldl from Tekmo's foldl package:
Control.Foldl.purely foldBChan :: MonadIO m => Fold a b -> BroadcastChan In a -> m (m b)
foldBChanM :: MonadIO m => (x -> a -> m x) -> m x -> (x -> m b) -> BroadcastChan In a -> m (m b) #
Strict, monadic fold of the BroadcastChan'
s elements. Can be used with
Control.Foldl from Tekmo's foldl package:
Control.Foldl.impurely foldBChanM :: MonadIO m => FoldM m a b -> BroadcastChan In a -> m (m b)