Game dev
Saved & recent

Coroutine

Related terms: yield, await, timer, multithreading

A function that can pause at a yield or await point and resume later with its local state intact. It makes sequences such as “open the door, wait, then close it” easier to express.

In common engine coroutine systems, the game loop keeps running while the coroutine waits. That does not make expensive work run on another thread: work before the next yield can still block a frame. Cancel pending sequences when their owner is gone.

Further reading
Unity: MonoBehaviour.StartCoroutine
open door close door yield resume suspended coroutine game frames
The coroutine opens the door, yields during a wait and resumes to close it. The game loop keeps running throughout the wait.

View in the full Game dev collection