feat: replace fiber run() with transfer() and suspend() for scheduler-friendly semantics
Remove the run() method from fibers and introduce transfer() for non-stack-based fiber switching, along with suspend() to pause the interpreter and return control to the host application. Update Timer.sleep() to use runNextScheduled_() instead of Fiber.yield(), and add Timer.schedule() for creating independently scheduled fibers. Refactor the core fiber runtime to support transfer semantics, including proper error handling for aborted fibers and self-transfer edge cases. Fix a missing quote in test.py's runtime error validation string.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
var a = Fiber.new {
|
||||
IO.print("a")
|
||||
}
|
||||
|
||||
var b = Fiber.new {
|
||||
IO.print("b before")
|
||||
a.transfer()
|
||||
IO.print("b after")
|
||||
}
|
||||
|
||||
var c = Fiber.new {
|
||||
IO.print("c before")
|
||||
b.transfer()
|
||||
IO.print("c after")
|
||||
}
|
||||
|
||||
IO.print("start") // expect: start
|
||||
|
||||
c.transfer()
|
||||
// expect: c before
|
||||
// expect: b before
|
||||
// expect: a
|
||||
|
||||
// Nothing else gets run since the interpreter stops after a completes.
|
||||
Reference in New Issue
Block a user