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.
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import "timer" for Timer
|
||||
|
||||
Fiber.new {
|
||||
Timer.schedule {
|
||||
Timer.sleep(2)
|
||||
IO.print("a")
|
||||
}.call()
|
||||
}
|
||||
|
||||
Fiber.new {
|
||||
Timer.schedule {
|
||||
Timer.sleep(1)
|
||||
IO.print("b")
|
||||
}.call()
|
||||
}
|
||||
|
||||
IO.print("main")
|
||||
Timer.sleep(3)
|
||||
|
||||
Reference in New Issue
Block a user