Hello :wave: Was just wondering about Flow and con...
# coroutines
d
Hello 👋 Was just wondering about Flow and context (https://kotlinlang.org/docs/flow.html#flow-context). I understand that we should not be emitting new values from new coroutines but is it fine to start coroutines to fetch some data or that should still fall under
channelFlow
? e.g.
Copy code
flowOf(1, 2, 3).map { 
  id -> coroutineScope {
    val first = async { retrieve(id) }
    val second = async { retrieveOther(id) }
    first.await() + second.await()
  }
}
l
Your snippet correct. That rule only applies to call to
emit
👍 1
d
thanks
l
The reason is that calling
emit
calls code from the collector side directly, and you'd not expect it to be cancelled by the upstream flow code or have it run on an unknown dispatcher.
In other words, the
emit
function calls the lambda of
collect
.
d
Thanks for the explanation