mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-12 22:10:46 -05:00
add Fut.get_or_fail{,_exn}
This commit is contained in:
parent
483392986c
commit
dd5a177a5f
2 changed files with 29 additions and 0 deletions
13
src/fut.ml
13
src/fut.ml
|
|
@ -28,6 +28,19 @@ let[@inline] peek self : _ option =
|
||||||
| Done x -> Some x
|
| Done x -> Some x
|
||||||
| Waiting _ -> None
|
| Waiting _ -> None
|
||||||
|
|
||||||
|
exception Not_ready
|
||||||
|
|
||||||
|
let[@inline] get_or_fail self =
|
||||||
|
match A.get self.st with
|
||||||
|
| Done x -> x
|
||||||
|
| Waiting _ -> raise Not_ready
|
||||||
|
|
||||||
|
let[@inline] get_or_fail_exn self =
|
||||||
|
match A.get self.st with
|
||||||
|
| Done (Ok x) -> x
|
||||||
|
| Done (Error (exn, bt)) -> Printexc.raise_with_backtrace exn bt
|
||||||
|
| Waiting _ -> raise Not_ready
|
||||||
|
|
||||||
let on_result (self : _ t) (f : _ waiter) : unit =
|
let on_result (self : _ t) (f : _ waiter) : unit =
|
||||||
while
|
while
|
||||||
let st = A.get self.st in
|
let st = A.get self.st in
|
||||||
|
|
|
||||||
16
src/fut.mli
16
src/fut.mli
|
|
@ -59,6 +59,22 @@ val peek : 'a t -> 'a or_error option
|
||||||
(** [peek fut] returns [Some r] if [fut] is currently resolved with [r],
|
(** [peek fut] returns [Some r] if [fut] is currently resolved with [r],
|
||||||
and [None] if [fut] is not resolved yet. *)
|
and [None] if [fut] is not resolved yet. *)
|
||||||
|
|
||||||
|
exception Not_ready
|
||||||
|
(** @since 0.2 *)
|
||||||
|
|
||||||
|
val get_or_fail : 'a t -> 'a or_error
|
||||||
|
(** [get_or_fail fut] obtains the result from [fut] if it's fulfilled
|
||||||
|
(i.e. if [peek fut] returns [Some res], [get_or_fail fut] returns [res]).
|
||||||
|
@raise Not_ready if the future is not ready.
|
||||||
|
@since 0.2 *)
|
||||||
|
|
||||||
|
val get_or_fail_exn : 'a t -> 'a
|
||||||
|
(** [get_or_fail_exn fut] obtains the result from [fut] if it's fulfilled,
|
||||||
|
like {!get_or_fail}. If the result is an [Error _], the exception inside
|
||||||
|
is re-raised.
|
||||||
|
@raise Not_ready if the future is not ready.
|
||||||
|
@since 0.2 *)
|
||||||
|
|
||||||
(** {2 Combinators} *)
|
(** {2 Combinators} *)
|
||||||
|
|
||||||
val spawn : on:Pool.t -> (unit -> 'a) -> 'a t
|
val spawn : on:Pool.t -> (unit -> 'a) -> 'a t
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue