https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

poohbar

10/10/2018, 4:21 PM
Copy code
fun <A, B> Sequence<A>.pmap(f: suspend (A) -> B): Sequence<B> = runBlocking {
    map { async(Dispatchers.Default) { f(it) } }.map { it.await() }
}
how come this says
Suspension function can be called only within couroutine body
on the
it.await()
call?
z

Zach Klippenstein (he/him) [MOD]

10/10/2018, 4:24 PM
@rocketraman basically just asked the same question right before you 😉 Since `Sequence`s are lazy, they can’t use inlined operators. And since the operators aren’t inlined, even if they’re used from within a suspend function the lambdas you pass to them can’t be suspending. What you really need for this is some kind of stream abstraction, like RxJava, which Kotlin doesn’t currently have (but see https://github.com/Kotlin/kotlinx.coroutines/issues/254 )
d

Dico

10/10/2018, 5:06 PM
For the time being, you can try using a Channel instead of a Sequence, like @Jonathan replied on the last question.
p

poohbar

10/10/2018, 6:19 PM
darn it it's like I need to have a PHD for this thing
4 Views