Tests for Timer.sleep().
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import "timer" for Timer
|
||||
|
||||
Fiber.new {
|
||||
Timer.sleep(2)
|
||||
IO.print("a")
|
||||
}.call()
|
||||
|
||||
Fiber.new {
|
||||
Timer.sleep(1)
|
||||
IO.print("b")
|
||||
}.call()
|
||||
|
||||
IO.print("main")
|
||||
Timer.sleep(3)
|
||||
IO.print("done")
|
||||
// expect: main
|
||||
// expect: b
|
||||
// expect: a
|
||||
// expect: done
|
||||
@@ -0,0 +1,20 @@
|
||||
import "timer" for Timer
|
||||
|
||||
// These are both rounded to 1, so "a" should complete first.
|
||||
Fiber.new {
|
||||
Timer.sleep(1.5)
|
||||
IO.print("a")
|
||||
}.call()
|
||||
|
||||
Fiber.new {
|
||||
Timer.sleep(1.3)
|
||||
IO.print("b")
|
||||
}.call()
|
||||
|
||||
IO.print("main")
|
||||
Timer.sleep(3)
|
||||
IO.print("done")
|
||||
// expect: main
|
||||
// expect: a
|
||||
// expect: b
|
||||
// expect: done
|
||||
@@ -0,0 +1,9 @@
|
||||
import "timer" for Timer
|
||||
|
||||
IO.print("1") // expect: 1
|
||||
Timer.sleep(3)
|
||||
IO.print("2") // expect: 2
|
||||
Timer.sleep(3)
|
||||
IO.print("3") // expect: 3
|
||||
Timer.sleep(3)
|
||||
IO.print("4") // expect: 4
|
||||
@@ -0,0 +1,3 @@
|
||||
import "timer" for Timer
|
||||
|
||||
Timer.sleep(-1) // expect runtime error: Milliseconds cannot be negative.
|
||||
@@ -0,0 +1,3 @@
|
||||
import "timer" for Timer
|
||||
|
||||
Timer.sleep("wat") // expect runtime error: Milliseconds must be a number.
|
||||
@@ -0,0 +1,27 @@
|
||||
import "timer" for Timer
|
||||
|
||||
Fiber.new {
|
||||
Timer.sleep(0)
|
||||
IO.print("a")
|
||||
}.call()
|
||||
|
||||
Fiber.new {
|
||||
Timer.sleep(0)
|
||||
IO.print("b")
|
||||
}.call()
|
||||
|
||||
Fiber.new {
|
||||
Timer.sleep(0)
|
||||
IO.print("c")
|
||||
}.call()
|
||||
|
||||
IO.print("main")
|
||||
Timer.sleep(0) // This is enough to let the other fiber run.
|
||||
IO.print("done")
|
||||
|
||||
// expect: main
|
||||
// Run in the order they were enqueued.
|
||||
// expect: a
|
||||
// expect: b
|
||||
// expect: c
|
||||
// expect: done
|
||||
Reference in New Issue
Block a user