Skip to content

Commit eba2394

Browse files
committed
add Fut.{cancel,try_cancel}
1 parent 213d9bd commit eba2394

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/core/fut.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ let make () =
1515
fut, fut
1616

1717
let[@inline] return x : _ t = C.returned x
18+
let[@inline] cancel x ebt = C.cancel x (fst ebt) (snd ebt)
19+
let[@inline] try_cancel x ebt = C.try_cancel x (fst ebt) (snd ebt)
1820

1921
let[@inline] fail exn bt : _ t =
2022
let fut = C.create () in

src/core/fut.mli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ val on_result_ignore : _ t -> (Exn_bt.t option -> unit) -> unit
5151

5252
exception Already_fulfilled
5353

54+
val try_cancel : _ promise -> Exn_bt.t -> bool
55+
(** [try_cancel promise ebt] tries to cancel the promise, returning [true]. It
56+
returns [false] if the promise is already resolved.
57+
@since NEXT_RELEASE *)
58+
59+
val cancel : _ promise -> Exn_bt.t -> unit
60+
(** Silent version of {!try_cancel}, ignoring the result.
61+
@since NEXT_RELEASE *)
62+
5463
val fulfill : 'a promise -> 'a or_error -> unit
5564
(** Fullfill the promise, setting the future at the same time.
5665
@raise Already_fulfilled if the promise is already fulfilled. *)

0 commit comments

Comments
 (0)