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

Safe HaskellSafe-Inferred
LanguageHaskell98

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 a Source

All of these must succeed

requireAny :: [Tree a] -> Tree a Source

Any of these must succeed

tryAll :: [Tree a] -> Tree a Source

As many as possible should succeed, try all.

Evaluating trees

evalTree :: forall a. Monoid a => (a -> Bool) -> Tree (Promise a) -> IO (a, a) Source

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

The first result is the failures, then the actual result comes

watchTree :: Monoid a => (a -> Bool) -> Tree (Promise a) -> IO (TChan a, 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. These failures are sent to the TChan.

Scheduling

interleave :: Tree a -> [a] Source

A simple scheduling (see workers)

interleave' :: Tree a -> [a] Source

A somewhat smarter scheduling (see workers)

Utilities

showTree :: Show a => Tree a -> String Source

Shows a tree