From eba239487c1e20a4320b55f81d3c36b8611b1380 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 21 May 2025 11:48:12 -0400 Subject: [PATCH] add Fut.{cancel,try_cancel} --- src/core/fut.ml | 2 ++ src/core/fut.mli | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/core/fut.ml b/src/core/fut.ml index 2ae34996..415e68ab 100644 --- a/src/core/fut.ml +++ b/src/core/fut.ml @@ -15,6 +15,8 @@ let make () = fut, fut let[@inline] return x : _ t = C.returned x +let[@inline] cancel x ebt = C.cancel x (fst ebt) (snd ebt) +let[@inline] try_cancel x ebt = C.try_cancel x (fst ebt) (snd ebt) let[@inline] fail exn bt : _ t = let fut = C.create () in diff --git a/src/core/fut.mli b/src/core/fut.mli index 6d667376..45c800df 100644 --- a/src/core/fut.mli +++ b/src/core/fut.mli @@ -51,6 +51,15 @@ val on_result_ignore : _ t -> (Exn_bt.t option -> unit) -> unit exception Already_fulfilled +val try_cancel : _ promise -> Exn_bt.t -> bool +(** [try_cancel promise ebt] tries to cancel the promise, returning [true]. It + returns [false] if the promise is already resolved. + @since NEXT_RELEASE *) + +val cancel : _ promise -> Exn_bt.t -> unit +(** Silent version of {!try_cancel}, ignoring the result. + @since NEXT_RELEASE *) + val fulfill : 'a promise -> 'a or_error -> unit (** Fullfill the promise, setting the future at the same time. @raise Already_fulfilled if the promise is already fulfilled. *)