feat: implement symmetric coroutines with fiber.call and fiber.run distinction

Add new `fiber.call` method that remembers the calling fiber for symmetric transfer, while `fiber.run` now performs tail-call style switching without preserving the caller. Introduce re-entrancy guards preventing a fiber from being called multiple times, update all test fixtures to use the new API, and add comprehensive test coverage for call semantics including direct/indirect re-entrancy, value passing, and finished fiber errors.
This commit is contained in:
Bob Nystrom
2014-04-14 14:23:05 +00:00
parent 71783400ae
commit 10b19d969b
31 changed files with 276 additions and 63 deletions
+10 -3
View File
@@ -1,6 +1,13 @@
var fiber = new Fiber {
var a = new Fiber {
IO.print("run")
}
fiber.run // expect: run
fiber.run // expect runtime error: Cannot run a finished fiber.
// Run a through an intermediate fiber since it will get discarded and we need
// to return to the main one after a completes.
var b = new Fiber {
a.run
IO.print("nope")
}
b.call // expect: run
a.run // expect runtime error: Cannot run a finished fiber.