Created
March 2, 2018 09:22
-
-
Save glaznaj/12ece300d2e7fab5adef2e82bf364019 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
use "time" | |
interface Fn | |
fun apply() | |
type Duration is U64 | |
primitive Second | |
fun apply(n: (U64 | USize)): Duration => | |
match n | |
| let s: U64 => s * 1_000_000_000 | |
| let s: USize => U64.from[USize](s) * 1_000_000_000 | |
end | |
class After | |
fun apply(duration: Duration, fn: Fn iso) => | |
let timers = Timers | |
let timer = Timer(AfterNotify(consume fn), duration) | |
timers(consume timer) | |
class AfterNotify is TimerNotify | |
let _fn: Fn iso | |
new iso create(fn: Fn iso) => | |
_fn = consume fn | |
fun ref apply(timer: Timer, count: U64): Bool => | |
_fn() | |
false | |
actor Main | |
new create(env: Env) => | |
let out = env.out | |
let messages = ["5"; "4"; "3"; "Ready"; "Steady"; "Go!"] | |
for (i, message) in messages.pairs() do | |
After(Second(i), recover this~print(out, message) end) | |
end | |
fun tag print(out: OutStream, s: String) => | |
out.print(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment