Class: Concurrent::UnbufferedChannel

Inherits:
Object
  • Object
show all
Defined in:
lib/concurrent/channel/unbuffered_channel.rb

Instance Method Summary collapse

Constructor Details

#initializeUnbufferedChannel

Returns a new instance of UnbufferedChannel.



6
7
8
# File 'lib/concurrent/channel/unbuffered_channel.rb', line 6

def initialize
  @probe_set = WaitableList.new
end

Instance Method Details

#popObject



19
20
21
22
23
# File 'lib/concurrent/channel/unbuffered_channel.rb', line 19

def pop
  probe = Channel::Probe.new
  select(probe)
  probe.value
end

#probe_set_sizeObject



10
11
12
# File 'lib/concurrent/channel/unbuffered_channel.rb', line 10

def probe_set_size
  @probe_set.size
end

#push(value) ⇒ Object



14
15
16
17
# File 'lib/concurrent/channel/unbuffered_channel.rb', line 14

def push(value)
  until @probe_set.take.set_unless_assigned(value, self)
  end
end

#remove_probe(probe) ⇒ Object



29
30
31
# File 'lib/concurrent/channel/unbuffered_channel.rb', line 29

def remove_probe(probe)
  @probe_set.delete(probe)
end

#select(probe) ⇒ Object



25
26
27
# File 'lib/concurrent/channel/unbuffered_channel.rb', line 25

def select(probe)
  @probe_set.put(probe)
end