Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Fiber.reset #85

Open
Goju-Ryu opened this issue Mar 11, 2024 · 1 comment
Open

Implement Fiber.reset #85

Goju-Ryu opened this issue Mar 11, 2024 · 1 comment

Comments

@Goju-Ryu
Copy link

When reading the concurrency section on fibers I had some trouble understanding why fiber.reset() and fiber.status() was called in example only defining a fiber called task. After reading through some documentation and testing in the playground I have come to the conclusion that it is probably an error of the documentation.

The examples in question are the following:

cyber/docs/docs.md

Lines 2364 to 2402 in f3bda25

### Reset state.
To reset a fiber to its initial state, invoke `reset()`. *Planned Feature*
When reset, the existing stack is unwinded, the program counter returns to the starting point, and the state is set to `.init`:
```cy
func fib(n int) int:
coyield n
if n < 2:
return n
return fib(n - 1) + fib(n - 2)
var task = coinit(fib, 10)
-- Progress the fiber...
print(coresume task) -- Prints "10"
print(coresume task) -- Prints "9"
print(coresume task) -- Prints "8"
-- Reset back to the start with the `.init` state.
fiber.reset()
print(coresume task) -- Prints "10"
```
### Rebinding arguments.
Arguments attached to the fiber can be rebinded with a different set of values. *Planned Feature*
This allows fiber reuse, instead of creating a new fiber:
```cy
var task = coinit(fib, 10)
-- Run task to completion.
var res = 0
while fiber.status() != .done:
res = coresume fiber
print res
fiber.reset()
fiber.bindArgs(20)
-- Run task again with the new argument...
```

@fubark
Copy link
Owner

fubark commented Mar 11, 2024

Yep, that's a typo. Also, Fiber.reset hasn't been implemented.

@fubark fubark changed the title Possible error in documentation fiber code examples Implement Fiber.reset Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants