File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 3333require 'concurrent/utilities'
3434
3535require 'concurrent/channel/probe'
36+ require 'concurrent/channel/channel'
3637require 'concurrent/channel/unbuffered_channel'
3738
3839require 'concurrent/cached_thread_pool'
Original file line number Diff line number Diff line change 1+ module Concurrent
2+ class Channel
3+ def self . select ( *channels )
4+ probe = Probe . new
5+
6+ channels . each { |channel | channel . select ( probe ) }
7+ probe . value
8+ end
9+ end
10+ end
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+
3+ module Concurrent
4+
5+ describe Channel do
6+
7+ describe '.select' do
8+
9+ context 'without timeout' do
10+ it 'returns the first value available on a channel' do
11+ channels = [ UnbufferedChannel . new , UnbufferedChannel . new ]
12+
13+ Thread . new { channels [ 1 ] . push 77 }
14+
15+ value = Channel . select ( *channels )
16+
17+ value . should eq 77
18+ end
19+ end
20+
21+ end
22+
23+ end
24+ end
You can’t perform that action at this time.
0 commit comments