Is there a relatively simple way to convert a chan...
# announcements
s
Is there a relatively simple way to convert a channel to a sequence? At present using a broadcast channel to send events through two separate coroutines for processing. I'm trying:
Copy code
sequence {
                    yield(channelSubscription.receive())
                }
but that errors out with:
Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope
d
Copy code
sequence {
    yield(runBlocking { channelSubscription.receive() })
}
s
So, you're defining another coroutine to do the actual processing? Is there any risk to do runBlocking. Doesn't that block the thread for the current coroutine. Without this, isn't receive a suspending function?
d
Sequences are blocking, so runBlocking isn't too bad.
There's no other way to do this (I think). Assuming you still want the laziness.
s
ah.. so lazy in evaluation, but blocking in retrieval/computation. the only way to get around it is just passing the channel through to the terminal consumer?
d
Yup
s
also, many thanks, largely got it working/got past some behavioral issues that were causing failures at a certain size