mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
add example program from discuss
This commit is contained in:
parent
6a44598a31
commit
a85bc80573
2 changed files with 39 additions and 0 deletions
27
examples/discuss1.ml
Normal file
27
examples/discuss1.ml
Normal file
|
|
@ -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
examples/dune
Normal file
12
examples/dune
Normal file
|
|
@ -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
|
||||||
|
))
|
||||||
Loading…
Add table
Reference in a new issue