macnixde
macnixde

Reputation: 241

How to pass the CoroutineScope to composed objects in Kotlin (Structured Concurrency)

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?

Upvotes: 1

Views: 341

Answers (0)

Related Questions