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

sbyrne

03/11/2019, 8:30 PM
Seems like I should be able to wrap a ReceiveChannel in a Sequence to pass it to another library.
o

octylFractal

03/11/2019, 8:52 PM
sequences are using coroutines for non-async purposes, so you can't do it without
runBlocking
or similar
it's probably not supported by default for this reason
s

sbyrne

03/11/2019, 8:58 PM
I want something like
launch { someExternalLibrary.process( channel.asSequence() ) }
o

octylFractal

03/11/2019, 9:01 PM
yes, but sequences are not coroutine-enabled outside of the
sequence {}
builder
so it's still blocking code
you could probably write a similar api to sequences, that is fully async, but there's not a current primitive for it, because I think ReceiveChannel already has a lot of the features in it
d

Dominaezzz

03/11/2019, 9:11 PM
Copy code
sequence {
    yield(runBlocking { channel.receive() })
}
4 Views