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

Safe HaskellSafe-Inferred
LanguageHaskell98

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

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

Is this a result?

isUnfinished :: PromiseResult a -> Bool Source

Is this unfinished?

isCancelled :: PromiseResult a -> Bool Source

Is this cancelled?

Combining results

eitherResult :: PromiseResult a -> PromiseResult a -> PromiseResult a Source

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.

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.