Structured Concurrency
Behind the scenes, each CoroutineScope has a CoroutineContext. Think of a coroutine context as the set of rules for how a coroutine should execute, and the coroutine scope as the overseer of a coroutine’s execution according to those rules. A CoroutineContext is further broken down into smaller components that define execution rules. The most commonly used elements that make up a coroutine context are a Job and a CoroutineDispatcher (Figure 20.1).
Figure 20.1 Anatomy of a CoroutineScope
A coroutine’s Job tracks information about the coroutine’s state, like whether it is running. It also ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd 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.