capnp-0.4.0.0: Cap'n Proto for Haskell

Safe HaskellNone
LanguageHaskell2010

Capnp.Rpc.Promise

Contents

Description

This module defines a Promise type, represents a value which is not yet available, and related utilities.

Synopsis

Documentation

data Promise a Source #

A promise is a value that may not be ready yet.

Instances
Eq (Promise a) Source # 
Instance details

Defined in Capnp.Rpc.Promise

Methods

(==) :: Promise a -> Promise a -> Bool #

(/=) :: Promise a -> Promise a -> Bool #

data Fulfiller a Source #

A Fulfiller is used to fulfill a promise.

Creating promises

newPromise :: MonadIO m => m (Promise a, Fulfiller a) Source #

Create a new promise and an associated fulfiller.

newPromiseWithCallback :: MonadIO m => (Either Exception a -> STM ()) -> m (Promise a, Fulfiller a) Source #

Create a new promise which also excecutes an STM action when it is resolved.

newCallback :: MonadIO m => (Either Exception a -> STM ()) -> m (Fulfiller a) Source #

Like newPromiseWithCallback, but doesn't return the promise.

newCallbackSTM :: (Either Exception a -> STM ()) -> STM (Fulfiller a) Source #

Like newCallback, but runs in STM.

Fulfilling or breaking promises

fulfill :: MonadIO m => Fulfiller a -> a -> m () Source #

Fulfill a promise by supplying the specified value. It is an error to call fulfill if the promise has already been fulfilled (or broken).

fulfillSTM :: Fulfiller a -> a -> STM () Source #

Like fulfill, but in STM

breakPromise :: MonadIO m => Fulfiller a -> Exception -> m () Source #

Break a promise. When the user of the promise executes wait, the specified exception will be raised. It is an error to call breakPromise if the promise has already been fulfilled (or broken).

Getting the value of a promise

wait :: MonadIO m => Promise a -> m a Source #

Wait for a promise to resolve, and return the result. If the promise is broken, this raises an exception instead (see breakPromise).

waitSTM :: Promise a -> STM a Source #

Like wait, but runs in STM.