Files
wren/test/timer/sleep_float.wren
Bob Nystrom 556af50f83 Revise low level fiber semantics to play nicer with schedulers.
Now that I'm starting to write a real async scheduler on top of Wren's
basic fiber API, I have a better feel for what it needs. It turns out
run() is not it.

- Remove run() methods.
- Add transfer() which leaves the caller of the invoked fiber alone.
- Add suspend() to return control to the host application.
- Add Timer.schedule() to start a new independently scheduled fiber.
- Change Timer.sleep() so that it only transfers control to explicitly
  scheduled fibers, not any one.
2015-08-30 22:15:37 -07:00

21 lines
305 B
Plaintext

import "timer" for Timer
// These are both rounded to 1, so "a" should complete first.
Timer.schedule {
Timer.sleep(1.5)
IO.print("a")
}
Timer.schedule {
Timer.sleep(1.3)
IO.print("b")
}
IO.print("main")
Timer.sleep(3)
IO.print("done")
// expect: main
// expect: a
// expect: b
// expect: done