package kcas_data

  1. Overview
  2. Docs

Module Kcas_data.PromiseSource

A promise of a value to be resolved at some point in the future.

Example:

  # let promise, resolver = Promise.create () in
    let domain = Domain.spawn @@ fun () ->
      Printf.printf "Got %d\n%!" (Promise.await promise)
    in
    Promise.resolve resolver 42;
    Domain.join domain
  Got 42
  - : unit = ()

Common interface

Sourcetype !+'a t

The type of a promise of a value of type 'a.

Sourcetype !-'a u

The type of a resolver of a value of type 'a.

Sourcetype 'a or_exn = ('a, exn) result t

The type of a promise of a result of type ('a, exn) result.

Sourceval create : unit -> 'a t * 'a u

create () returns a new unresolved pair of a promise and a resolver for the promise.

Sourceval create_resolved : 'a -> 'a t

create_resolved x returns a promise that is already resolved to the given value x.

Compositional interface

Sourcemodule Xt : sig ... end

Explicit transaction log passing on promises.

Non-compositional interface

Sourceval resolve : 'a u -> 'a -> unit

resolve u v resolves the promise corresponding to the resolver u to the value v. Any awaiters of the corresponding promise are then unblocked.

Sourceval await : 'a t -> 'a

await t either immediately returns the resolved value of the promise t or blocks until the promise t is resolved.

Sourceval peek : 'a t -> 'a option

peek t immediately returns either the resolved value of the promise t or None in case the promise hasn't yet been resolved.

Sourceval is_resolved : 'a t -> bool

is_resolved t determines whether the promise t has already been resolved.

Result promises

Sourceval await_exn : 'a or_exn -> 'a

await_exn t is equivalent to match await t with v -> v | exception e -> raise e.

Sourceval resolve_ok : ('a, 'b) result u -> 'a -> unit

resolve_ok u v is equivalent to resolve u (Ok v).

Sourceval resolve_error : ('a, 'b) result u -> 'b -> unit

resolve_error u e is equivalent to resolve u (Error e).

OCaml

Innovation. Community. Security.