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



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

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
18
# File 'lib/concurrent/channel/unbuffered_channel.rb', line 14

def push(value)
  # TODO set_unless_assigned define on IVar as #set_state? or #try_set_state
  until @probe_set.take.set_unless_assigned(value, self)
  end
end

#remove_probe(probe) ⇒ Object



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

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

#select(probe) ⇒ Object



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

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