I have the following: ```suspend fun fooFlow(): Fl...
# coroutines
r
I have the following:
Copy code
suspend 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
Copy code
Type mismatch.
Required: FlowCollector<List<Foo>>
Found: (Nothing) -> Unit
s
collect
is a suspending function….
onFooEmission
must be suspending as well… or create a Coroutine inside
onFooEmission
and call
collect
from that Coroutine
r
My apologies,
onFooEmission
is a
CoroutineScope
extension and
fooFlow()
is a
suspend
s
You’d still need to call
launch
first, though…
Copy code
fun CoroutineScope.onFooEmission(action: (List<Foo>) -> Unit) {
  launch { fooFlow().collect { foos -> action(foos) } }
}
r
You’re right, I accidentally omitted a bunch of things. But that still doesn’t resolve my issue
I still have the same error with everything you outlined above
s
It works fine in Android Studio:
Copy code
fun fooFlow(): Flow<List<Foo>> = TODO()

fun CoroutineScope.onFooEmission(action: (List<Foo>) -> Unit) {
    launch {
        fooFlow().collect { foos ->
            action(foos)
        }
    }
}
Be sure to
import kotlinx.coroutines.flow.collect
, though!
r
Looks like my auto-import just completely failed. Manually importing the dependency worked just fine. Thanks!
d
Yeah, getting extension functions to auto-import when they have the same name as interface functions is a big pain. I guess this is why star imports exist, though my team tries to avoid them.