Is there a way to use select (or some other simila...
# coroutines
m
Is there a way to use select (or some other similar mechanism) to select for messages on an arbitrary set of Channels not known at compile time (provided the channels have the same message type)?
o
what's wrong with using
select
?
you can just do
for (c in list) c.onX {}
m
Ah, I hadn't found any docs which did something like that, wasn't sure if calling onReceive in a loop in a select block would do what I want
If it will, awesome
It looked like you had to explicitly do select<Type> { foo.onReceive... bar.onReceive... baz.onReceive... ....
o
there's no magic language feature, it's just library code , so I presume it will work because it's just like listing individually
b
The following works as well
Copy code
val receivingA: SelectClause1<Foo> = channel.onReceive
select { // this: SelectBuilder<Foo>
    receivingA { it }
}
The key thing is that you
invoke
on the SelectClause returned by the
onReceive
property from inside of the
SelectBuilder
context