load os load random const N = 10; const C = 1; var ichan = mt::Channel(C) var schan = mt::Channel(C) var fut = mt.start { var index = 0; io.writeln( "begin producing" ) while( ++index <= N ){ if( random.rand(2) ){ io.writeln( "sending integer:", index ); ichan.send( index ) }else{ io.writeln( "sending string: index_" + (string) index ); schan.send( "index_" + (string) index ) } #os.sleep(0.5) } io.writeln( "end producing" ) ichan.cap(0) # set channel buffer size to zero to close the channel; schan.cap(0) } var selects = { ichan => 0, schan => 0, fut => 0 } io.writeln( "begin consuming" ) while( 1 ){ io.writeln( "before selecting" ); var data = mt::select( selects, 0.2 ) io.writeln( "received:", data ); if( data.status == $finished ) break } io.writeln( "end consuming" )