feat fut: add join

This commit is contained in:
Simon Cruanes 2023-06-12 22:06:43 -04:00
parent 0177d6aee7
commit 7c853861d8
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 6 additions and 0 deletions

View file

@ -143,6 +143,8 @@ let bind ?on ~f fut : _ t =
fut2 fut2
let join ?on fut = bind ?on fut ~f:(fun x -> x)
let update_ (st : 'a A.t) f : 'a = let update_ (st : 'a A.t) f : 'a =
let rec loop () = let rec loop () =
let x = A.get st in let x = A.get st in

View file

@ -77,6 +77,10 @@ val bind : ?on:Pool.t -> f:('a -> 'b t) -> 'a t -> 'b t
and fails with [e] if [fut] fails with [e] or [f x] raises [e]. and fails with [e] if [fut] fails with [e] or [f x] raises [e].
@param on if provided, [f] runs on the given pool *) @param on if provided, [f] runs on the given pool *)
val join : ?on:Pool.t -> 'a t t -> 'a t
(** [join fut] is [fut >>= Fun.id]. It joins the inner layer of the future.
@since 0.2 *)
val both : 'a t -> 'b t -> ('a * 'b) t val both : 'a t -> 'b t -> ('a * 'b) t
(** [both a b] succeeds with [x, y] if [a] succeeds with [x] and (** [both a b] succeeds with [x, y] if [a] succeeds with [x] and
[b] succeeds with [y], or fails if any of them fails. *) [b] succeeds with [y], or fails if any of them fails. *)