Vivek Rajendran
03/12/2025, 1:30 PMclass Feature(parentScope: CoroutineScope) {
...
}
or
class Feature(parentContext: CoroutineContext): CoroutineScope {
override val coroutineContext = parentContext + SupervisorJob()
...
}
Dmitry Khalanskiy [JB]
03/12/2025, 1:44 PMFeature
. parentScope
controls that. In (2), you have to look at the source code to determine how the Job
passed in parentContext
is used, and the answer, surprisingly, is that it's not used at all. There's a third option: create a SupervisorJob
whose parent job is taken from parentContext
, which will allow cancelling the coroutines from the outside at least, but that is still less self-evident than (1).Vivek Rajendran
03/12/2025, 1:46 PM