Method: Channel.select

Defined in:
lib/channel.rb

.select(*channels) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/channel.rb', line 95

def select(*channels)
  selector = new
  threads = channels.map do |c|
    Thread.new { selector << [c.recv, c] }
  end
  yield selector.recv
ensure
  selector.close
  threads.each(&:kill).each(&:join)
end