Module Sel.Promise

Simple promise library for synchronization. There is no critical section support: if two threads run if not (is_resolved p) then fulfill r the behavior is undefined. Use only in a 1 producer 1 consumer scenario.

type 'a state =
  1. | Fulfilled of 'a
  2. | Rejected of exn
val pp_state : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a state -> unit
type 'a t
val pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
type 'a handler
val make : unit -> 'a t * 'a handler

make () is a new promise and handler to resolve it.

val get : 'a t -> 'a state

get p is the state of the resolved promise.

  • raises [Failure]

    if not resolved

val is_resolved : 'a t -> bool

is_resolved p is true if fulfill or reject was called

val fulfill : 'a handler -> 'a -> unit

fulfill r v fulfills the promise with v.

  • raises [Failure]

    if already resolved

val reject : 'a handler -> exn -> unit

reject r e rejects the promise p with e.

  • raises [Failure]

    if already resolved