From f76b713556af85a2a1677ebe97a5d61b214f788f Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 15 Jun 2023 10:24:20 -0400 Subject: [PATCH] add Fut.is_done --- src/fut.ml | 5 +++++ src/fut.mli | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/fut.ml b/src/fut.ml index 7c2d199d..4e3ddbd8 100644 --- a/src/fut.ml +++ b/src/fut.ml @@ -28,6 +28,11 @@ let[@inline] peek self : _ option = | Done x -> Some x | Waiting _ -> None +let[@inline] is_done self : bool = + match A.get self.st with + | Done _ -> true + | Waiting _ -> false + exception Not_ready let[@inline] get_or_fail self = diff --git a/src/fut.mli b/src/fut.mli index 16cf1979..01390c1c 100644 --- a/src/fut.mli +++ b/src/fut.mli @@ -75,6 +75,10 @@ val get_or_fail_exn : 'a t -> 'a @raise Not_ready if the future is not ready. @since 0.2 *) +val is_done : _ t -> bool +(** Is the future resolved? This is the same as [peek fut |> Option.is_some]. + @since 0.2 *) + (** {2 Combinators} *) val spawn : on:Pool.t -> (unit -> 'a) -> 'a t