1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
(* TEST *)
open Effect
open Effect.Deep
type _ t += Stop : unit t
let f count =
let r = ref 0 in
for i = 1 to count do
incr r;
if i = count / 2 then perform Stop
done;
!r
let _ =
let l = lazy (f 1_000) in
let v1 =
try_with Lazy.force l
{ effc = fun (type a) (e : a t) ->
match e with
| Stop -> Some (fun (k : (a, _) continuation) -> continue k ())
| _ -> None }
in
Printf.printf "%d\n" v1;
let l2 = lazy (f 2_000) in
let v2 =
try_with Lazy.force l2
{ effc = fun (type a) (e : a t) ->
match e with
| Stop -> Some (fun (k : (a, _) continuation) ->
let d = Domain.spawn(fun () -> continue k ()) in
Domain.join d)
| _ -> None }
in
Printf.printf "%d\n" v2;
let l3 = lazy (f 3_000) in
let _ =
try_with Lazy.force l3
{ effc = fun (type a) (e : a t) ->
match e with
| Stop -> Some (fun _ ->
try
let d = Domain.spawn(fun () -> Lazy.force l3) in
Domain.join d
with CamlinternalLazy.Undefined -> Printf.printf "Undefined\n"; 0)
| _ -> None }
in
()
|