Structured concurrency and Lua (part 3)
John Belmonte, 2022-Oct
In the previous installment, we demonstrated how structured concurrency enables magical tracebacks, spanning both stack frames and task hierarchy. Not only do we regain the ability to diagnose errors, but since exceptions propagate through the nursery of each task, we also have Lua's full protected-call facility at our disposal—just as if the code was not using coroutines.
Nurseries are powerful because they let us orchestrate a set of tasks, ensuring that their lifetime is well-understood, and allowing every task to properly finalize on cancellation of the group. Cancellation can happen if one of the child tasks has an exception, or is otherwise explicitly requested. Explicit cancellation turns out to be fairly common—done just as often as exiting imperative code loops.
Here, we'll try to gain a