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) -> Unit
streetsofboston
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 suspend
streetsofboston
08/23/2019, 8:00 PMlaunch
first, though…fun CoroutineScope.onFooEmission(action: (List<Foo>) -> Unit) {
launch { fooFlow().collect { foos -> action(foos) } }
}
rook
08/23/2019, 8:01 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)
}
}
}
import kotlinx.coroutines.flow.collect
, though!rook
08/23/2019, 8:13 PMDavid Glasser
08/24/2019, 5:01 AM