https://kotlinlang.org logo
#announcements
Title
# announcements
h

haroldadmin

06/28/2019, 4:40 PM
What coroutine scope do you use to launch coroutines in classes that don’t necessarily have a lifecycle? I’m creating a NotificationManager class in an Android application, and I need to use coroutines for taking some database related tasks off the main thread. This class will be used as a singleton in the project via dependency injection. • Should I implement the Coroutine Scope interface in it? There will be no lifecycle callback to cancel the running coroutines in this scope, though • Should I just use GlobalScope if I don’t have a way to cleanup resources anyway?
r

Ruckus

06/28/2019, 5:08 PM
#coroutines
h

haroldadmin

06/28/2019, 5:19 PM
My apologies, I’ll post there.
g

gildor

06/29/2019, 6:36 AM
I prefer to pass coroutine scope to constructor of this class for such cases and just use some application level scope, even if this scope is never cancelled practically
👍 1
If you don't care about keeping this semantics you can of course use GlobalScope, but I believe that it make it less flexible
7 Views