feat: allow yielding main fiber and expose current fiber reference
- Change Fiber.yield() to exit interpreter when no parent fiber exists instead of raising runtime error - Add Fiber.current primitive to return the currently executing fiber object - Update interpreter loop to stop execution when PRIM_RUN_FIBER receives null value - Modify test expectations to reflect new yielding behavior from main fiber
This commit is contained in:
@@ -13,6 +13,10 @@ fiber is run. Does not immediately start running the fiber.
|
||||
IO.print("I won't get printed")
|
||||
}
|
||||
|
||||
### Fiber.**current**
|
||||
|
||||
The currently executing fiber.
|
||||
|
||||
### Fiber.**yield**()
|
||||
|
||||
Pauses the current fiber and transfers control to the parent fiber. "Parent"
|
||||
@@ -45,14 +49,13 @@ If a yielded fiber is resumed by calling `call()` or `run()` with an argument,
|
||||
If it was resumed by calling `call()` or `run()` with no argument, it returns
|
||||
`null`.
|
||||
|
||||
It is a runtime error to call this when there is no parent fiber to return to.
|
||||
If there is no parent fiber to return to, this exits the interpreter. This can
|
||||
be useful to pause execution until the host application wants to resume it
|
||||
later.
|
||||
|
||||
:::dart
|
||||
Fiber.yield() // ERROR
|
||||
|
||||
new Fiber {
|
||||
Fiber.yield() // ERROR
|
||||
}.run()
|
||||
Fiber.yield()
|
||||
IO.print("this does not get reached")
|
||||
|
||||
### Fiber.**yield**(value)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user