forked from robur-coop/miou
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67b9ee0
commit 7985775
Showing
8 changed files
with
148 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(vendored_dirs meio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(executable | ||
(name main) | ||
(libraries miou miou.unix)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
let woops_sleepy () = | ||
Miou.call_cc (fun () -> | ||
(* Woops! Wrong sleep function, we blocked the fiber *) | ||
Miou.meow "Sleepy task"; | ||
Unix.sleepf 5.; | ||
Miou_unix.sleep 10.) | ||
|
||
let spawn min max = | ||
(* Some GC action *) | ||
Miou.meow "Spawning task"; | ||
for _i = 0 to 100 do | ||
ignore (Sys.opaque_identity @@ Array.init 1000000 float_of_int) | ||
done; | ||
let mious = List.init (max - min) (fun i -> | ||
let i = min + i in | ||
let m = Miou.call_cc (fun () -> | ||
Miou.meow ("Spawning task " ^ string_of_int i); | ||
for _i = 0 to max do | ||
(* Some more GC action *) | ||
for _i = 0 to 100 do | ||
ignore (Sys.opaque_identity @@ Array.init 1000000 float_of_int) | ||
done; | ||
Miou_unix.sleep 0.2; | ||
Miou.yield () | ||
done; | ||
Miou_unix.sleep (float_of_int i)) | ||
in | ||
Miou_unix.sleep (float_of_int (max - i)); | ||
m) | ||
in | ||
mious | ||
|
||
(* Based on the Tokio Console example application *) | ||
let main () = | ||
Miou.meow "Main!"; | ||
let f () = spawn 5 10 in | ||
let g () = spawn 10 30 in | ||
let h () = woops_sleepy () in | ||
Miou.await_all (g () @ f () @ [ h () ] ) |> List.iter (fun v -> assert (v = Ok ())) | ||
|
||
let () = | ||
Miou_unix.run @@ fun () -> | ||
main () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.