broadcast-chan-pipes-0.1.0: Pipes-based parallel streaming code for broadcast-chan

Copyright(C) 2014-2018 Merijn Verstraaten
LicenseBSD-style (see the file LICENSE)
MaintainerMerijn Verstraaten <merijn@inconsistent.nl>
Stabilityexperimental
Portabilityhaha
Safe HaskellSafe
LanguageHaskell2010

BroadcastChan.Pipes

Contents

Description

This module is identical to BroadcastChan, but replaces BroadcastChan.parMapM_ with parMapM and parMapM_ which create a parallel processing producer and effect, respectively.

Synopsis

Documentation

data Action #

Action to take when an exception occurs while processing an element.

Constructors

Drop

Drop the current element and continue processing.

Retry

Retry by appending the current element to the queue of remaining elements.

Terminate

Stop all processing and reraise the exception.

Instances
Eq Action 
Instance details

Methods

(==) :: Action -> Action -> Bool #

(/=) :: Action -> Action -> Bool #

Show Action 
Instance details

data Handler (m :: * -> *) a #

Exception handler for parallel processing.

Constructors

Simple Action

Always take the specified Action.

Handle (a -> SomeException -> m Action)

Allow inspection of the element, exception, and execution of monadic actions before deciding the Action to take.

parMapM Source #

Arguments

:: MonadSafe m 
=> Handler IO a

Exception handler

-> Int

Number of parallel threads to use

-> (a -> IO b)

Function to run in parallel

-> Producer a m ()

Input producer

-> Producer b m () 

Create a producer that processes its inputs in parallel.

This function does *NOT* guarantee that input elements are processed or output in a deterministic order!

parMapM_ Source #

Arguments

:: MonadSafe m 
=> Handler IO a

Exception handler

-> Int

Number of parallel threads to use

-> (a -> IO ())

Function to run in parallel

-> Producer a m r

Input producer

-> Effect m r 

Create an Effect that processes its 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) 
Instance details

Methods

(==) :: BroadcastChan d a -> BroadcastChan d a -> Bool #

(/=) :: BroadcastChan d a -> BroadcastChan d a -> Bool #

data Direction #

Used with DataKinds as phantom type indicating whether a BroadcastChan value is a read or write end.

Constructors

In

Indicates a write BroadcastChan

Out

Indicates a read BroadcastChan

type In = In #

Alias for the In type from the Direction kind, allows users to write the BroadcastChan In a type without enabling DataKinds.

type Out = Out #

Alias for the Out type from the Direction kind, allows users to write the BroadcastChan Out a type without enabling DataKinds.

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)