I want to use a specific `CoroutineScope` in my cl...
# dagger
p
I want to use a specific
CoroutineScope
in my class. Should I inject scope or rather
CoroutineDispatcher
and use
withContext
for testing purposes?
j
It depends. Maybe both! A scope is for ownership of the work, and coroutine contexts are for moving where the work runs. You don't need a scope if your public API is suspend and you don't need work to continue after the function calls complete. If the work extends past the function calls, or you want a non-suspend API, you need a scope. If you can't rely on the implicit dispatcher in the scope, then you should also inject a coroutine context (which will contain a dispatcher), such as for I/O.
🍺 2