



Scala Coroutines is a library-level extension for the Scala programming language that introduces first-class coroutines.

Coroutines are a language abstraction that generalizes subroutines (i.e. procedures, methods or functions). Unlike a subroutine, which is invoked once and executes until it completed, a coroutine can pause execution and yield control back to the caller, or another coroutine. The caller can then resume the coroutine when appropriate. Coroutines have a number of use cases, including but not limited to:

data structure iterators

event-driven code without the inversion of control

cooperative multitasking

concurrency frameworks such as actors, async-await and dataflow networks

expressing asynchrony, and better composition of asynchronous systems

capturing continuations

expressing backtracking algorithms

AI agents such as behavior trees

To learn how to use coroutines, please see the Scala Coroutines Guide in the documentation section.