Skip to content

Instantly share code, notes, and snippets.

@glaznaj
Created March 2, 2018 09:22
Show Gist options
  • Save glaznaj/12ece300d2e7fab5adef2e82bf364019 to your computer and use it in GitHub Desktop.
Save glaznaj/12ece300d2e7fab5adef2e82bf364019 to your computer and use it in GitHub Desktop.
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