15 Structured concurrency

This chapter covers

  • Establishing hierarchies between coroutines via the concept of structured concurrency
  • How structured concurrency gives you fine-grained control over execution and cancellation of your code, automatically propagating cancellation across the coroutine hierarchy
  • The relationship between the coroutine context and structured concurrency
  • Writing code that behaves correctly when cancelled

When you use Kotlin coroutines in the context of real applications, chances are you will be managing a lot of coroutines. Major challenges when working with many concurrent operations are keeping track of the individual tasks that are running, cancelling them when they’re no longer needed, and making sure that errors ...

Get Kotlin in Action, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.