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

Kroppeb

09/15/2019, 2:27 PM
Is there a way to use a select expression with something that's not a channel?
d

Dominaezzz

09/15/2019, 2:30 PM
Yes! You can select on anything (using the right abstraction)!
What about
ByteReadChannel
do you want to select?
k

Kroppeb

09/15/2019, 2:36 PM
Well it's a custom type I'm reading
But it gives an error,
Suspend functions can only be called within a coroutine body
Looking at
onReceive()
It seems I need a
SelectClauseX
?
d

Dominaezzz

09/15/2019, 2:44 PM
You'll basically have to wrap the call in
async
and select using the
onAwait
.
You could also implement your own select clause but iirc it's experimental and there little docs about writing them.
k

Kroppeb

09/15/2019, 2:52 PM
thanks
4 Views