lean4-htt/tests/lean/run/task_test_io.lean
2021-01-27 14:45:31 +01:00

35 lines
910 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#eval id (α := IO _) do
let t1 ← IO.asTask $ Nat.forM 10 fun _ => IO.println "hi";
let t2 ← IO.asTask $ Nat.forM 10 fun _ => IO.println "ho";
IO.ofExcept t1.get
#eval id (α := IO _) do
let t1 ← IO.mapTask IO.println (Task.spawn fun _ => "ha");
pure ()
#eval id (α := IO _) do
let t1 ← IO.bindTask (Task.spawn fun _ => "hu") fun s =>
IO.asTask (IO.println s);
pure ()
#eval id (α := IO _) do
let t1 ← IO.asTask do {
let c ← IO.checkCanceled;
IO.println (if c then "canceled!" else "done!")
};
pure ()
#eval id (α := IO _) do
let t1 ← IO.asTask do {
let c ← IO.checkCanceled;
IO.println (if c then "canceled! 2" else "done! 2")
};
IO.cancel t1;
discard $ IO.wait t1;
pure ()
#eval IO.waitAny [
Task.spawn fun _ => dbgSleep 2 fun _ => "A",
Task.spawn fun _ => dbgSleep 3 fun _ => "B",
Task.spawn fun _ => dbgSleep 1 fun _ => "C"
]