liveBook · Manning

Suspension point

As explained in Kotlin in Action, 2E

A suspension point is a point at which a suspending coroutine can pause and allow other coroutines sharing its dispatcher to execute.

A suspension point is where a suspending coroutine pauses, freeing its dispatcher thread so other coroutines can run. The coroutine later resumes from its saved state. section 14.6.2

Interleaving coroutines on one thread

In a runBlocking block, one launch calls delay(100.milliseconds). That call suspends the second coroutine, allowing a third coroutine to log and finish before the second resumes. The coroutines interleave without parallel execution.

Suspension points also shape cancellation, flow collection, and coroutine tests:

  • Receive CancellationException at suspension points when a coroutine is cancelled; avoid swallowing it with broad exception handlers. section 15.2.4
  • Stop a flow collector at the next cancellation point; emit is both a suspension and cancellation point. section 16.2.3
  • Let sibling coroutines run in runTest by providing suspension points such as delay or yield; use virtual-time controls for scheduled work. section 18.5.1

How Kotlin in Action, 2E covers it

How deep it goes
Explains scheduling, compiler-generated state restoration, cancellation behavior, flow effects, and testing implications without detailing compiler transformations.
Examples
Uses launch with delay, cancellation of a flow collector, broad exception handling, and runTest scheduling examples.
What it assumes
Assumes basic coroutines, launch, delay, and runBlocking; teaches how pausing enables other coroutine work.
What you can do after
Diagnose coroutine ordering, preserve cancellation, stop flow collection, and coordinate coroutine tests with suspension or virtual-time controls.
How it connects
Connects suspension points with coroutines, dispatchers, cancellation, flows, structured concurrency, and virtual time.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kotlin in Action, 2E. The section links point to the parts of the book it draws on.