Dominaezzz
10/10/2019, 10:19 AMcoroutineScope
vs withContext
question. Does coroutineScope
change the coroutineContext
like withContext
does? (I'm referring to the intrinsic coroutineContext
and not CoroutineScope.coroutineContext
). The docs aren't explicit enough to inspire confidence.gildor
10/10/2019, 10:22 AMcoroutineContext
function creates a new coroutine with own Job (same as withContext actually)Dominaezzz
10/10/2019, 10:24 AMflow { coroutineScope { emit(...) } }
will not work then?gildor
10/10/2019, 10:29 AMelizarov
10/10/2019, 11:29 AMflow { coroutineScope { emit(....) } }
is allowed. Even though coroutinesScope { ... }
creates a new job and a new context with it, it is considered an continuation of its parent context that runs sequentially with it. This is specifically allowed to make it possible to write:
flow {
coroutineScope {
// can launch concurrent stuff here
launch { ... }
// but can only emit sequentially from here
emit(...)
}
}