Code on a screen, representing a coroutine.

A function that can pause and resume.

What a coroutine is

A coroutine is a generalization of a function that can pause its own execution and resume later from where it left off. An ordinary function runs from start to finish each time it is called, but a coroutine can suspend partway through, hand control elsewhere, and then continue later from the same point. This ability to pause and resume makes coroutines a flexible tool for structuring programs.

Pausing and resuming

The defining feature of a coroutine is that it can suspend and resume. When a coroutine pauses, it remembers where it was, so that when it is resumed, it picks up exactly from that point rather than starting over. This lets a coroutine do some work, step aside to let other code run, and then come back to continue its work seamlessly.

Coroutines versus ordinary functions

An ordinary function has a single entry and runs to completion before returning. A coroutine, by contrast, has the ability to yield control in the middle and be re-entered later. This difference gives coroutines more flexibility in how control flows through a program, allowing patterns that are awkward to express with plain functions that cannot pause.

Cooperative multitasking

Coroutines are often used for cooperative multitasking, where different pieces of work voluntarily pause to let others proceed. Because a coroutine chooses when to yield, multiple coroutines can take turns running, cooperating to share the processor. This is a lightweight way to handle many tasks that need to make progress without each one running to completion before the next begins.

Where coroutines are used

Coroutines appear in many programming languages and are useful for tasks that involve waiting, interleaving work, or producing a sequence of results over time. Their ability to pause and resume makes them well suited to such situations. Understanding coroutines clarifies a flexible model of execution that goes beyond the run-to-completion behavior of ordinary functions.

Why it matters

The coroutine is an important concept in programming. Understanding what it is - a function that can pause and resume - clarifies a flexible way to structure work and enable cooperative multitasking. For anyone interested in how programs manage concurrent work, it is a valuable concept to understand.

See also: What is a thread in programming?, What is a function in programming?.

Sources

Published date reflects the original event date (2026-10-12). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.

Skillo Staff

Skillo Staff

All stories by: Skillo Staff

Leave a Reply