| Safe Haskell | Safe |
|---|---|
| Language | Haskell98 |
Pipes.Concurrent
Description
Asynchronous communication between pipes
- newtype Input a = Input {}
- newtype Output a = Output {}
- fromInput :: MonadIO m => Input a -> Producer' a m ()
- toOutput :: MonadIO m => Output a -> Consumer' a m ()
- spawn :: Buffer a -> IO (Output a, Input a)
- spawn' :: Buffer a -> IO (Output a, Input a, STM ())
- withSpawn :: Buffer a -> ((Output a, Input a) -> IO r) -> IO r
- withBuffer :: Buffer a -> (Output a -> IO l) -> (Input a -> IO r) -> IO (l, r)
- data Buffer a
- unbounded :: Buffer a
- bounded :: Int -> Buffer a
- latest :: a -> Buffer a
- newest :: Int -> Buffer a
- module Control.Concurrent
- module Control.Concurrent.STM
- module System.Mem
Inputs and Outputs
Pipe utilities
Actors
spawn :: Buffer a -> IO (Output a, Input a) Source #
Spawn a mailbox using the specified Buffer to store messages
- fails and returns
Falseif the mailbox is sealed, otherwise it: - retries if the mailbox is full, or:
- adds a message to the mailbox and returns
True.
- retrieves a message from the mailbox wrapped in
Justif the mailbox is not empty, otherwise it: - retries if the mailbox is not sealed, or:
- fails and returns
Nothing.
If either the Input or Output is garbage collected the mailbox will
become sealed.
spawn' :: Buffer a -> IO (Output a, Input a, STM ()) Source #
Like spawn, but also returns an action to manually seal the mailbox
early:
(output, input, seal) <- spawn' buffer ...
Use the seal action to allow early cleanup of readers and writers to the
mailbox without waiting for the next garbage collection cycle.
withSpawn :: Buffer a -> ((Output a, Input a) -> IO r) -> IO r Source #
withSpawn passes its enclosed action an Output and Input like you'd get from spawn,
but automatically seals them after the action completes. This can be used when you need the
sealing behavior available from 'spawn\'', but want to work at a bit higher level:
withSpawn buffer $ \(output, input) -> ...
withSpawn is exception-safe, since it uses bracket internally.
withBuffer :: Buffer a -> (Output a -> IO l) -> (Input a -> IO r) -> IO (l, r) Source #
A more restrictive alternative to withSpawn that prevents deadlocks
Buffer specifies how to buffer messages stored within the mailbox
bounded :: Int -> Buffer a Source #
Store a bounded number of messages, specified by the Int argument
newest :: Int -> Buffer a Source #
Like Bounded, but send never fails (the buffer is never full).
Instead, old elements are discarded to make room for new elements
Re-exports
Control.Concurrent re-exports forkIO, although I recommend using the
async library instead.
Control.Concurrent.STM re-exports atomically and STM.
System.Mem re-exports performGC.
module Control.Concurrent
module Control.Concurrent.STM
module System.Mem