Coroutines
Coroutines are special functions that can pause execution to allow other code to run, and resume execution form where it left off.
const coro = () => {
var x = 0
while (true) {
yield x
x += 1
}
}
const c = coro() // This sets up and returns a ready coroutine
c().println() // 0
c().println() // 1
c().println() // 2const coro = () => {
var x = 5
while (true) {
yield x + _value
}
}
const c = coro() // This sets up and returns a ready coroutine
c(5).println() // 10
c(3).println() // 8
c().println() // This will not error, because the previous call has already set the _value to 3. If the first coroutine call did not provide a valid argument, an error will then be raisedChecking Coroutine State
Last updated