eprocess-1.5.1: *Very* basic Erlang-like process support for Haskell

Control.Concurrent.Process

Contents

Description

This module provides a *very* basic support for processes with message queues. It was built using channels and MVars.

Synopsis

Types

data ReceiverT r m a Source

The ReceiverT generic type.

r
the type of things the process will receive
m
the monad in which it will run
a
the classic monad parameter

data Handle r Source

A Process handle. It's returned on process creation and should be used | afterwards to send messages to it

type Process r = ReceiverT r IOSource

Process are receivers that run in the IO Monad

Functions

Process creation / destruction

makeProcess :: (m t -> IO s) -> ReceiverT r m t -> Process r sSource

makeProcess builds a process from a code that generates an IO action. Usage: process <- makeProcess evalFunction receiver

runHereSource

Arguments

:: MonadIO m 
=> Process r t

The process to be run

-> m t

It's returned as an action

runHere executes process code in the current environment. Usage: result <- runHere process

spawnSource

Arguments

:: MonadIO m 
=> Process r k

The process to be run

-> m (Handle r)

The handle for that process

spawn starts a process and returns its handle. Usage: handle <- spawn process

killSource

Arguments

:: MonadIO m 
=> Handle a

The handle of process to kill

-> m () 

kill lets you *brutally* terminate a running process. Usage: kill processHandle

Message passing

self :: Monad m => ReceiverT r m (Handle r)Source

self returns the handle of the current process. Usage: handle <- self

sendToSource

Arguments

:: MonadIO m 
=> Handle a

The receiver process handle

-> a

The message to send

-> m () 

sendTo lets you send a message to a running process. Usage: sendTo processHandle message

recv :: MonadIO m => ReceiverT r m rSource

recv lets you receive a message in a running process (it's a blocking receive). Usage: message <- recv

recvInSource

Arguments

:: MonadIO m 
=> Int

milliseconds to wait until timeout

-> ReceiverT r m (Maybe r) 

Just like recv but with a timeout parameter. Usage: maybeMessage <- recv

sendRecvSource

Arguments

:: MonadIO m 
=> Handle a

The receiver process handle

-> a

The message to send

-> ReceiverT r m r

The process where this action is run will wait until it receives something

sendRecv is just a syntactic sugar for: sendTo h a >> recv