Skip to content

Commit 46531d7

Browse files
committed
Channel.select removes old probes
1 parent abdcd1b commit 46531d7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/concurrent/channel/channel.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ module Concurrent
22
class Channel
33
def self.select(*channels)
44
probe = Probe.new
5-
65
channels.each { |channel| channel.select(probe) }
7-
probe.value
6+
result = probe.value
7+
channels.each { |channel| channel.remove_probe(probe) }
8+
result
89
end
910
end
1011
end

spec/concurrent/channel/channel_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ module Concurrent
1616

1717
value.should eq 77
1818
end
19+
20+
it 'cleans up' do
21+
channels = [ UnbufferedChannel.new, UnbufferedChannel.new]
22+
channels.each { |ch| ch.stub(:remove_probe).with( an_instance_of(Probe) )}
23+
24+
Thread.new { channels[1].push 77 }
25+
26+
value = Channel.select(*channels)
27+
28+
value.should eq 77
29+
30+
channels.each { |ch| expect(ch).to have_received(:remove_probe).with( an_instance_of(Probe) ) }
31+
end
1932
end
2033

2134
end

0 commit comments

Comments
 (0)