val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Ppx_sexp_conv_lib.Sexp.tinclude Core_kernel.Invariant.S1 with type 'a t := 'a t
val invariant : ('a -> unit) -> 'a t -> unitcreate f calls f i, where i is an empty ivar. create returns a deferred that becomes determined when f fills i.
val upon : 'a t -> ('a -> unit) -> unitupon t f will run f v at some point after t becomes determined with value v.
val peek : 'a t -> 'a optionpeek t returns Some v iff t is determined with value v.
val value_exn : 'a t -> 'avalue_exn t returns v if t is determined with value v, and raises otherwise.
val is_determined : 'a t -> boolis_determined t returns true iff t is determined.
Deferreds form a monad.
include Core_kernel.Monad with type 'a t := 'a t
t >>= f returns a computation that sequences the computations represented by two monad elements. The resulting computation first does t to yield a value v, and then runs the computation returned by f v.
module Monad_infix : sig ... endval return : 'a -> 'a treturn v returns the (trivial) computation that returns v.
ignore_m t is map t ~f:(fun _ -> ()). ignore_m used to be called ignore, but we decided that was a bad name, because it shadowed the widely used Caml.ignore. Some monads still do let ignore = ignore_m for historical reasons.
module Let_syntax : sig ... endmodule Infix : sig ... endval unit : unit tunit is a deferred that is always determined with value ()
val never : unit -> _ tnever () returns a deferred that never becomes determined.
both t1 t2 becomes determined after both t1 and t2 become determined.
all ts returns a deferred that becomes determined when every t in ts is determined. The output is in the same order as the input.
any ts returns a deferred that is determined when any of the underlying deferreds is determined.
any_unit is like any, but ignores results of the component deferreds.
val don't_wait_for : unit t -> unitdon't_wait_for t ignores t. It is like Fn.ignore, but is more constrained because it requires a unit Deferred.t.
Rather than ignore (t : _ t), do don't_wait_for (Deferred.ignore t).
We chose to give don't_wait_for type unit t rather than _ t to catch errors where a value is accidentally ignored.
module Choice : sig ... endA Choice.t is used to produce an argument to enabled or choose. See below.
type 'a choice = 'a Choice.tenabled [choice t1 f1; ... choice tn fn;] returns a deferred d that becomes determined when any of the ti becomes determined. The value of d is a function f that when called, for each ti that is enabled, applies fi to ti, and returns a list of the results. It is guaranteed that the list is in the same order as the choices supplied to enabled, but of course it may be shorter than the input list if not all ti are determined.
choose [ choice t1 f1
; ...
; choice tn fn ] returns a deferred t that becomes determined with value fi ai after some ti becomes determined with value ai. It is guaranteed that choose calls at most one of the fis, the one that determines its result. There is no guarantee that the ti that becomes determined earliest in time will be the one whose value determines the choose. Nor is it guaranteed that the value in t is the first value (in place order) from choices that is determined at the time t is examined.
For example, in:
choose [ choice t1 (fun () -> `X1)
; choice t2 (fun () -> `X2) ]
>>> function
| `X1 -> e1
| `X2 -> e2 it may be the case that both t1 and t2 become determined, yet e2 actually runs.
It is guaranteed that if multiple choices are determined with no intervening asynchrony, then the earliest choice in the list will become the value of the choose.
for_ start ~to_:stop ~do_:f is the deferred analog of:
for i = start to stop do
f i;
done val repeat_until_finished : 'state -> ('state -> [ `Repeat of 'state | `Finished of 'result ] t) -> 'result trepeat_until_finished initial_state f repeatedly runs f until f returns `Finished. The first call to f happens immediately when repeat_until_finished is called.
val forever : 'state -> ('state -> 'state t) -> unitforever initial_state f repeatedly runs f, supplying the state returned to the next call to f.
val ok : 'a t -> ('a, _) Core_kernel.Result.t tUseful for lifting values from the Deferred.t monad to the Result.t Deferred.t monad.
Deferred collections
module Array : sig ... endmodule List : sig ... endmodule Map : sig ... endmodule Memo : sig ... endMemoization functions like in Core_kernel.Memo, with re-raising of exceptions thrown asynchronously.
module Queue : sig ... endAll Deferred_queue iteration functions first copy the queue (to a list) and then start calling the user function f. So, if f modifies the queue, that will have no effect on the iteration.
module Sequence : sig ... endError-carrying deferreds
module Option : sig ... endmodule Or_error : sig ... endThe deferred analog of Core.Or_error. It is exposed in std.ml as Deferred.Or_error.
module Result : sig ... end