add Fut.{cancel,try_cancel}
Some checks failed
github pages / Deploy doc (push) Has been cancelled
Build and Test / build (push) Has been cancelled
Build and Test / build-compat (push) Has been cancelled
Build and Test / format (push) Has been cancelled

This commit is contained in:
Simon Cruanes 2025-05-21 11:48:12 -04:00
parent 213d9bdd19
commit eba239487c
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 11 additions and 0 deletions

View file

@ -15,6 +15,8 @@ let make () =
fut, fut fut, fut
let[@inline] return x : _ t = C.returned x 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[@inline] fail exn bt : _ t =
let fut = C.create () in let fut = C.create () in

View file

@ -51,6 +51,15 @@ val on_result_ignore : _ t -> (Exn_bt.t option -> unit) -> unit
exception Already_fulfilled 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 val fulfill : 'a promise -> 'a or_error -> unit
(** Fullfill the promise, setting the future at the same time. (** Fullfill the promise, setting the future at the same time.
@raise Already_fulfilled if the promise is already fulfilled. *) @raise Already_fulfilled if the promise is already fulfilled. *)