Why does CoroutineScope exist?

Viewed 31

As far as design reasoning goes, why did the authors of Kotlin's coroutine library decide to create CoroutineScope? As far as I can tell, it really only serves as a receiver for coroutine builders that holds a CoroutineContext, as well as some pass through functions to that context's elements. Even a scope's cancellation is just a passthrough call to the context's job.

Did the authors just want to reserve the right to add more things to a scope later? Can't the current iteration of coroutines effectively just cut the scope out and make a CoroutineContext both the receiver and the container for a simpler design?

1 Answers

As Roman Elizarov himself (lead of the coroutines library dev team at the time) described in his article, the difference is their intended purpose.

They effectively contain the same stuff, but they are used in different ways, and giving such interfaces different names allowed to manipulate them more easily and in particular define function signatures more clearly.

Related