caf-0.0.3: A library of Concurrency Abstractions using Futures.

Portabilityportable
Stabilityprovisional
Maintainersabel@ki.cs.uni-frankfurt.de; willig@ki.cs.uni-frankfurt.de

Control.Concurrent.Futures.Futures

Description

This module implements explicit futures (EFuture, efuture, force) as well as several variants of implicit futures (future, recursiveFuture, strictFuture, strictRecursiveFuture, lazyFuture, lazyRecursiveFuture) While explicit futures must be forced (using force) if their value is needed, this is not necessary for implicit futures. For implicit futures it is necessary to put them into the global wrapper withFuturesDo.

Synopsis

Documentation

type EFuture a = MVar aSource

The type EFuture implements explicit futures, i.e. if the value of the future is need it must be forced explicitly using force

efuture :: IO a -> IO (EFuture a)Source

efuture creates an explicit future, i.e. the computation is performed concurrently. The future value can be forced using force

force :: EFuture a -> IO aSource

force forces the value of an explicit future (EFuture), i.e. the calling thread blocks until the result becomes available.

future :: IO a -> IO aSource

future creates an implicit future. A non-blocking concurrent computation is started. If the value of the future is needed, then the future will be forced implicitly. The concurrent computation is killed if the calling thread stops, even if future is used within withFuturesDo.

recursiveFuture :: (a -> IO a) -> IO aSource

recursiveFuture behaves similar to future with the difference that the future is recursive, i.e. the future created by recursiveFuture is used as argument of the code of the future.

withFuturesDo :: IO () -> IO ()Source

withFuturesDo is the global wrapper which should be used around the code involving futures. I.e., instead of writing main=code one should use main=withFuturesDo code. Note, that there should be only one call to withFuturesDo in a program.

strictFuture :: IO a -> IO aSource

creating a strict future is similar to future with the difference that if used inside withFuturesDo it is guaranteed that the concurrent computation is forced (and finished) before the main thread terminates. Warning: strictFuture should only be used within the global wrapper withFuturesDo!

strictRecursiveFuture :: (a -> IO a) -> IO aSource

a recursive variant of strictFuture (see recursiveFuture and 'future) Warning: strictRecursiveFuture should only be used within the global wrapper withFuturesDo!

lazyFuture :: IO a -> IO aSource

a lazy future. Initially, no concurrent computation is started, but if the lazy future gets (implicitly) forced, then the lazy future becomes a strict future. Warning: lazyFuture should only be used within the global wrapper withFuturesDo!

lazyRecursiveFuture :: (a -> IO a) -> IO aSource

a recursive variant of lazyFuture (see recursiveFuture and 'future) Warning: lazyRecursiveFuture should only be used within the global wrapper withFuturesDo!

hbind :: (t -> t1) -> t -> t1Source

binds a handle to its value.

newhandled :: IO (a -> IO (), a)Source

creates a new handle.

bhandle :: (a -> (a -> IO ()) -> t) -> IO tSource

a new handle component.