Tour · 16 of 18
Suspension
The program on the right waits one millisecond, then prints.
#Suspending functions
fn ready!() -> string $ Clock:
sleep!(1ms)
"ready"A timer, file or server may make a function wait while other work runs.
Such a function ends in !, and so does every call that waits, like
sleep!(1ms).
#Up to main!
pub fn main!() -> void $ Clock + Console:
println(ready!())The ! travels up to main!, so every pause point is visible. main!
names the clock and console it uses as $ Clock + Console.
Run it. ready! sleeps 1 ms and returns, so it prints ready.
Try it: change fn ready!() -> string $ Clock: to fn ready() -> string $ Clock: and press Run.
Run: Ctrl+Enter · Pages: Alt+← Alt+→