Here's much better version:
///
// First, a simple fibre to copy from one channel to another
noinline proc copy[T] (i:ischannel[T],o:oschannel[T]) ()
{
while true do
var x = read i;
write (o,x);
done
}
// Now, here's a multiplexor.
proc mux[T] (inp:1->opt[ischannel[T]]
here's how to do something like select(), i.e. read from one of several
channels, which every is ready first:
proc multiplex (i1:ischannel[int], i2:ischannel[int], o:oschannel[int]) {
spawn_fthread { while true do var x = read i1; write (o,x); done };
spawn_fthread { while true do var x = read