load random const N = 100; var chans = { mt::Channel(1), mt::Channel(1) } mt.start { var index = 0; io.writeln( "begin producing" ) while( ++index <= N ){ if( random.rand(2) ){ io.writeln( "sending integer:", index ); chans[0].send( index ) }else{ io.writeln( "sending string: index_" + (string) index ); chans[1].send( "index_" + (string) index ) } } io.writeln( "end producing" ) chans[0].cap(0) # set channel buffer size to zero to close the channel; chans[1].cap(0) } var select = mt::Channel(1) mt.start { var f1 = mt.start { while(1){ var data = chans[0].receive(); if( data.status == $finished ) break select.send( (int) data.data ) } } var f2 = mt.start { while(1){ var data = chans[1].receive(); if( data.status == $finished ) break select.send( (string) data.data ) } } f1.wait() f2.wait() select.cap(0) # set channel buffer size to zero to close the channel; } io.writeln( "begin consuming" ) while(1){ var data = select.receive() io.writeln( "received", data ); if( data.status == $finished ) break } io.writeln( "end consuming" )