stm-promise-0.0.1.1: Simple STM Promises for IO computations and external processes

Safe HaskellNone

Control.Concurrent.STM.Promise.Tree

Contents

Description

A tree of computation

Synopsis

Trees

data Tree a Source

Both/Either-trees

Constructors

Node Label (Tree a) (Tree a)

Combine two trees with the semantics of Label

Leaf a

A computation

Recoverable (Tree a)

There is a mean of recovering this computation, by returning mempty

Instances

data Label Source

Both/Either labels

Constructors

Both

Both of these must succeed with an An

Either

Either of these must succeed with an An, and that one is returned

Creating trees

requireAll :: [Tree a] -> Tree aSource

All of these must succeed

requireAny :: [Tree a] -> Tree aSource

Any of these must succeed

tryAll :: [Tree a] -> Tree aSource

As many as possible should succeed, try all.

Evaluating trees

evalTree :: Monoid a => (a -> Bool) -> Tree (Promise a) -> IO (Maybe a)Source

Evaluates a tree of promises, cutting of unnecessary branches, given that some other thread(s) evaluates the promises.

The first argument is the same as for watchTree. Is currently implemented in terms of watchTree, rather than something more efficient (such as TMVars).

watchTree :: Monoid a => (a -> Bool) -> Tree (Promise a) -> IO (DTVar (Tree (PromiseResult a)))Source

Assuming some other thread(s) evaluate the promises in the tree, this gives a live view of the progress, and cancels unnecessary subtrees (due to Either).

The first argument is a way to deem promises with results as failures. `(== mempty)` or (const False) could be good alternatives.

Scheduling

interleave :: Tree a -> [a]Source

A simple scheduling (see workers)

Utilities

showTree :: Show a => Tree a -> StringSource

Shows a tree