Reputation: 241
I have a Kotlin application main class which provides a CoroutineScope
. The main class creates various instances of other classes (composition), all of which should use the scope from the main class in order to implement proper structured concurrently patterns and enable a clean cancellation/shutdown..
NB: some of the child classes need to launch
some background monitoring tasks in their initializer. So they need to have the coroutineScope available at class level.
What is the best and most idiomatic way to pass the scope to the component classes?
CoroutineScope
(having its own lifetime) and cancel that scope from the main class (risk of forgetting to cancel)Upvotes: 1
Views: 341