is it common practice to pass around a coroutine c...
# coroutines
d
is it common practice to pass around a coroutine context? I come from the C# world, and I’m trying to figure out how to actually call suspend functions
e
kotlin.coroutines.CoroutineContext
is pretty low level, you generally don't need to think about it
kotlinx.coroutines.CoroutineScope
uses
kotlin.coroutines.CoroutineContext
as a building block for structured concurrency; there's other users too
but assuming you're working with
kotlinx.coroutines
, about whether to pass a
kotlinx.coroutines.CoroutineScope
or not, see https://medium.com/@elizarov/coroutine-context-and-scope-c8b255d59055
g
To call suspend function you need a suspend block, the easiest way to create is use any of default coroutine builders, such as launch/async/runBlocking
u
for me I divider objects into those who have state and scope, and those who "do" things the first own their own coroutine scope and the latter just has suspend functions, no state, no dispatchers, just pure suspend functions the first objects own the second types
g
Not sure that it's correct separation. It's completely fine for suspend function to has blocks with scopes and dispatchers inside
u
well, different view, worked for me. Repos do stuff. ViewModels / Managers own state/scope/disposables