Extra-1.46.3: A grab bag of modules.

Safe HaskellSafe-Inferred
LanguageHaskell98

Extra.IOThread

Description

this module provides a simple mechanism for adding IO operations to a queue and running them in a single thread. This is useful if the IO operations have side-effects which could collide if run from multiple threads. For example, creating an image thumbnail and storing it on disk, running latex, etc.

Synopsis

Documentation

newtype IOThread a b Source

Constructors

IOThread (Chan (a, MVar (Either SomeException b))) 

startIOThread Source

Arguments

:: (a -> IO b)

the IO function that does all the work

-> IO (ThreadId, IOThread a b)

a ThreadId which can be used to kill the IOThread, and a handle that can be used to issue requests to the thread.

start the IO thread.

ioRequest Source

Arguments

:: IOThread a b

handle to the IOThread

-> a

argument to the function in the IOThread

-> IO b

value returned by the function in the IOThread

issue a request to the IO thread and get back the result if the thread function throws an exception ioRequest will rethrow the exception.