What coroutine scope do you use to launch coroutin...
# announcements
h
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
#coroutines
h
My apologies, I’ll post there.
g
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