rook
08/23/2019, 7:55 PMsuspend fun fooFlow(): Flow<List<Foo>>
fun CoroutineScope.onFooEmission(action: (List<Foo>) -> Unit) {
launch {
fooFlow().collect { foos -> action(foos) }
}
}
But at the collect call-site, I’m getting Type mismatch.
Required: FlowCollector<List<Foo>>
Found: (Nothing) -> Unitstreetsofboston
08/23/2019, 7:57 PMcollect is a suspending function…. onFooEmission must be suspending as well… or create a Coroutine inside onFooEmission and call collect from that Coroutinerook
08/23/2019, 7:59 PMonFooEmission is a CoroutineScope extension and fooFlow() is a suspendstreetsofboston
08/23/2019, 8:00 PMlaunch first, though…streetsofboston
08/23/2019, 8:00 PMfun CoroutineScope.onFooEmission(action: (List<Foo>) -> Unit) {
launch { fooFlow().collect { foos -> action(foos) } }
}rook
08/23/2019, 8:01 PMrook
08/23/2019, 8:02 PMstreetsofboston
08/23/2019, 8:03 PMfun fooFlow(): Flow<List<Foo>> = TODO()
fun CoroutineScope.onFooEmission(action: (List<Foo>) -> Unit) {
launch {
fooFlow().collect { foos ->
action(foos)
}
}
}streetsofboston
08/23/2019, 8:04 PMimport kotlinx.coroutines.flow.collect, though!rook
08/23/2019, 8:13 PMDavid Glasser
08/24/2019, 5:01 AM