Coroutines
Coroutines are special functions that can pause execution to allow other code to run, and resume execution form where it left off.
Vortex functions become coroutines when the yield
statement is found within their body.
Calling a coroutine function returns a function that is ready for execution.
Coroutines expose a hidden variable called _value
. This variable starts off as the value None, however if we pass an argument into the coroutine function, it gets assigned to value.
If a coroutine finishes execution, ie. there are no more yield statements, it is considered to be done and any further calls will simply return None
.
You can manually end a coroutine by including a return statement in the function's body.
Checking Coroutine State
Calling the builtin function info
on the coroutine will show you its state:
The info
call provides information about the function, including whether or not it is a generator (coroutine), if it has been initialised or not, and if it has finished its execution.
Last updated