Skip to content

Commit

Permalink
add example program from discuss
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Oct 3, 2024
1 parent 6a44598 commit a85bc80
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/discuss1.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(** Example from https://discuss.ocaml.org/t/confused-about-moonpool-cancellation/15381 *)

let ( let@ ) = ( @@ )

let () =
let@ () = Trace_tef.with_setup () in
let@ _ = Moonpool_fib.main in

(* let@ runner = Moonpool.Ws_pool.with_ () in *)
let@ runner = Moonpool.Background_thread.with_ () in

(* Pretend this is some long-running read loop *)
for i = 1 to 10 do
Printf.printf "MAIN LOOP %d\n%!" i;
Moonpool_fib.check_if_cancelled ();
let _ : _ Moonpool_fib.t =
Moonpool_fib.spawn ~on:runner ~protect:false (fun () ->
Printf.printf "RUN FIBER %d\n%!" i;
Moonpool_fib.check_if_cancelled ();
Format.printf "FIBER %d NOT CANCELLED YET@." i;
failwith "BOOM")
in
Moonpool_fib.yield ();
(* Thread.delay 0.2; *)
(* Thread.delay 0.0001; *)
()
done
12 changes: 12 additions & 0 deletions examples/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(executables
(names discuss1)
(enabled_if
(>= %{ocaml_version} 5.0))
;(package moonpool)
(libraries
moonpool
moonpool.fib
trace
trace-tef
;tracy-client.trace
))

0 comments on commit a85bc80

Please sign in to comment.