From 9709f88d5fa6c1b296bec05d70f9ba9cd6764180 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 7 Nov 2023 20:38:27 -0500 Subject: [PATCH] breaking: fut: `join` does not take `?on` anymore --- src/fut.ml | 12 ++++++++++-- src/fut.mli | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/fut.ml b/src/fut.ml index ad34cefe..0e235f77 100644 --- a/src/fut.ml +++ b/src/fut.ml @@ -123,7 +123,6 @@ let map ?on ~f fut : _ t = Error (e, bt)) | Error e_bt -> Error e_bt in - match peek fut with | Some r -> of_result (map_res r) | None -> @@ -137,7 +136,17 @@ let map ?on ~f fut : _ t = match on with | None -> map_and_fulfill () | Some on -> Runner.run_async on map_and_fulfill); + fut2 +let join (fut : 'a t t) : 'a t = + match peek fut with + | Some (Ok f) -> f + | Some (Error (e, bt)) -> fail e bt + | None -> + let fut2, promise = make () in + on_result fut (function + | Ok sub_fut -> on_result sub_fut (fulfill promise) + | Error _ as e -> fulfill promise e); fut2 let bind ?on ~f fut : _ t = @@ -175,7 +184,6 @@ let bind ?on ~f fut : _ t = fut2 let bind_reify_error ?on ~f fut : _ t = bind ?on ~f (reify_error fut) -let join ?on fut = bind ?on fut ~f:(fun x -> x) let update_ (st : 'a A.t) f : 'a = let rec loop () = diff --git a/src/fut.mli b/src/fut.mli index 99b04a8d..989d43a6 100644 --- a/src/fut.mli +++ b/src/fut.mli @@ -120,7 +120,7 @@ val bind_reify_error : ?on:Runner.t -> f:('a or_error -> 'b t) -> 'a t -> 'b t @param on if provided, [f] runs on the given runner @since 0.4 *) -val join : ?on:Runner.t -> 'a t t -> 'a t +val join : 'a t t -> 'a t (** [join fut] is [fut >>= Fun.id]. It joins the inner layer of the future. @since 0.2 *)