mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-12 14:00:41 -05:00
cancellation in main
This commit is contained in:
parent
b47da2396e
commit
b208506841
2 changed files with 11 additions and 7 deletions
|
|
@ -10,7 +10,7 @@ type cancel_callback = Exn_bt.t -> unit
|
||||||
let prom_of_fut : 'a Fut.t -> 'a Fut.promise =
|
let prom_of_fut : 'a Fut.t -> 'a Fut.promise =
|
||||||
Fut.Private_.unsafe_promise_of_fut
|
Fut.Private_.unsafe_promise_of_fut
|
||||||
|
|
||||||
module Private_ = struct
|
module Private0 = struct
|
||||||
type 'a t = {
|
type 'a t = {
|
||||||
id: Handle.t; (** unique identifier for this fiber *)
|
id: Handle.t; (** unique identifier for this fiber *)
|
||||||
state: 'a state A.t; (** Current state in the lifetime of the fiber *)
|
state: 'a state A.t; (** Current state in the lifetime of the fiber *)
|
||||||
|
|
@ -40,13 +40,9 @@ module Private_ = struct
|
||||||
match A.get self.state with
|
match A.get self.state with
|
||||||
| Alive _ -> false
|
| Alive _ -> false
|
||||||
| Terminating_or_done _ -> true
|
| Terminating_or_done _ -> true
|
||||||
|
|
||||||
let cancel_from_outside (self : _ t) ebt : unit =
|
|
||||||
Fut.fulfill_idempotent (Fut.Private_.unsafe_promise_of_fut self.res)
|
|
||||||
@@ Error ebt
|
|
||||||
end
|
end
|
||||||
|
|
||||||
include Private_
|
include Private0
|
||||||
|
|
||||||
let create_ ~ls ~runner () : 'a t =
|
let create_ ~ls ~runner () : 'a t =
|
||||||
let id = Handle.generate_fresh () in
|
let id = Handle.generate_fresh () in
|
||||||
|
|
@ -321,3 +317,9 @@ let yield () : unit =
|
||||||
check_if_cancelled_ self;
|
check_if_cancelled_ self;
|
||||||
Suspend_.yield ();
|
Suspend_.yield ();
|
||||||
check_if_cancelled_ self
|
check_if_cancelled_ self
|
||||||
|
|
||||||
|
module Private_ = struct
|
||||||
|
include Private0
|
||||||
|
|
||||||
|
let cancel_from_outside = resolve_as_failed_
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ let main (f : Runner.t -> 'a) : 'a =
|
||||||
Fiber.on_result fiber (fun _ -> Runner.shutdown_without_waiting runner);
|
Fiber.on_result fiber (fun _ -> Runner.shutdown_without_waiting runner);
|
||||||
(* run the main thread *)
|
(* run the main thread *)
|
||||||
Fifo_pool.Private_.run_thread st runner ~on_exn:(fun e bt ->
|
Fifo_pool.Private_.run_thread st runner ~on_exn:(fun e bt ->
|
||||||
raise (Oh_no (Exn_bt.make e bt)));
|
let ebt = Exn_bt.make e bt in
|
||||||
|
Fiber.Private_.cancel_from_outside fiber ebt;
|
||||||
|
raise (Oh_no ebt));
|
||||||
match Fiber.peek fiber with
|
match Fiber.peek fiber with
|
||||||
| Some (Ok x) -> x
|
| Some (Ok x) -> x
|
||||||
| Some (Error ebt) -> Exn_bt.raise ebt
|
| Some (Error ebt) -> Exn_bt.raise ebt
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue