The coroutine module

The coroutine module provides a way to create and manage coroutines. A coroutine is a function that can be suspended and resumed. When a coroutine is resumed, it continues from the point where it was suspended. Coroutines are an implementation of cooperative multitasking.

Free functions

create(function: callable, args: list): coroutine

Creates a new coroutine. The coroutine will execute the given function with the given arguments. If args is not given, the function will be called without arguments.

Member functions

lastResult(self): string

Returns the last thing returned by step.

lastYielded(self): any

Returns the last thing yielded by the coroutine, if any.

run(self): null

Performs step until the coroutine returns something other than continue.

runAtMost(self, n: number): null

Performs step at most n times or until the coroutine returns something other than continue.

step(self): string

Performs a single step of the coroutine. If the coroutine is suspended, it will be resumed. Returns the status of the coroutine. The status can be one of the following: