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

Safe HaskellSafe-Inferred

Control.Concurrent.STM.Promise

Contents

Description

Promises that allow spawning and cancelling in IO, and an STM result

Synopsis

Promises

data Promise a Source

A promise

Constructors

Promise 

Fields

spawn :: IO ()

Instruction for spawning

cancel :: IO ()

Instruction for cancelling

result :: STM (PromiseResult a)

The result of a computation

Instances

an :: PromiseResult a -> aSource

Gets the result (partial function)

Results

data PromiseResult a Source

The result of the promise

Constructors

Unfinished

Not finished yet (or not even spawned yet))

Cancelled

Cancelled

An a

A result

Querying results

isAn :: PromiseResult a -> BoolSource

Is this a result?

isUnfinished :: PromiseResult a -> BoolSource

Is this unfinished?

isCancelled :: PromiseResult a -> BoolSource

Is this cancelled?

Combining results

eitherResult :: PromiseResult a -> PromiseResult a -> PromiseResult aSource

If either is finished (An), return one of them (favor the first one)

If either is Unfinished, this is also Unfinished.

Otherwise, both are Cancelled and so is this.

eitherResult' :: Monoid a => (a -> Bool) -> PromiseResult a -> PromiseResult a -> PromiseResult aSource

As eitherResult, but upon only one returned failure, waits for the other, and then either mappends the results or returns the failure if it is Cancelled.

mempty is not used.

bothResults :: PromiseResult a -> PromiseResult b -> PromiseResult (a, b)Source

If both are finished (An), return them in a tuple.

If either is Cancelled, this is also Cancelled.

Otherwise, both are Unfinished and so is this.

bothResults' :: Monoid a => (a -> Bool) -> PromiseResult a -> PromiseResult a -> PromiseResult aSource

Prefers to return failures than Cancelled

mempty is not used.