Parent

Files

Class/Module Index [+]

Quicksearch

Concurrent::Channel::BlockingRingBuffer

@api Channel @!macro edge_warning

Public Class Methods

new(capacity) click to toggle source
# File lib/concurrent/channel/blocking_ring_buffer.rb, line 10
def initialize(capacity)
  super()
  synchronize { ns_initialize capacity}
end

Public Instance Methods

capacity() click to toggle source

@return [Integer] the capacity of the buffer

# File lib/concurrent/channel/blocking_ring_buffer.rb, line 16
def capacity
  synchronize { @buffer.capacity }
end
count() click to toggle source

@return [Integer] the number of elements currently in the buffer

# File lib/concurrent/channel/blocking_ring_buffer.rb, line 21
def count
  synchronize { @buffer.count }
end
empty?() click to toggle source

@return [Boolean] true if buffer is empty, false otherwise

# File lib/concurrent/channel/blocking_ring_buffer.rb, line 26
def empty?
  synchronize { @buffer.empty? }
end
full?() click to toggle source

@return [Boolean] true if buffer is full, false otherwise

# File lib/concurrent/channel/blocking_ring_buffer.rb, line 31
def full?
  synchronize { @buffer.full? }
end
peek() click to toggle source

@return [Object] the first available value and without removing it from

the buffer. If buffer is empty returns nil
# File lib/concurrent/channel/blocking_ring_buffer.rb, line 59
def peek
  synchronize { @buffer.peek }
end
put(value) click to toggle source

@param [Object] value the value to be inserted @return [Boolean] true if value has been inserted, false otherwise

# File lib/concurrent/channel/blocking_ring_buffer.rb, line 37
def put(value)
  synchronize do
    wait_while_full
    @buffer.offer(value)
    ns_signal
    true
  end
end
take() click to toggle source

@return [Object] the first available value and removes it from the buffer.

If buffer is empty it blocks until an element is available
# File lib/concurrent/channel/blocking_ring_buffer.rb, line 48
def take
  synchronize do
    wait_while_empty
    result = @buffer.poll
    ns_signal
    result
  end
end

Protected Instance Methods

ns_initialize(capacity) click to toggle source
# File lib/concurrent/channel/blocking_ring_buffer.rb, line 65
def ns_initialize(capacity)
  @buffer = RingBuffer.new(capacity)
  @first = @last = 0
  @count = 0
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.