non-thread safe buffer
@api Channel @!macro edge_warning
@return [Integer] the capacity of the buffer
# File lib/concurrent/channel/ring_buffer.rb, line 18 def capacity @buffer.size end
@return [Integer] the number of elements currently in the buffer
# File lib/concurrent/channel/ring_buffer.rb, line 23 def count @count end
@return [Boolean] true if buffer is empty, false otherwise
# File lib/concurrent/channel/ring_buffer.rb, line 28 def empty? @count == 0 end
@return [Boolean] true if buffer is full, false otherwise
# File lib/concurrent/channel/ring_buffer.rb, line 33 def full? @count == capacity end
@param [Object] value @return [Boolean] true if value has been inserted, false otherwise
# File lib/concurrent/channel/ring_buffer.rb, line 39 def offer(value) return false if full? @buffer[@last] = value @last = (@last + 1) % @buffer.size @count += 1 true end
@return [Object] the first available value and without removing it from
the buffer. If buffer is empty returns nil
# File lib/concurrent/channel/ring_buffer.rb, line 59 def peek @buffer[@first] end
@return [Object] the first available value and removes it from the buffer. If buffer is empty returns nil
# File lib/concurrent/channel/ring_buffer.rb, line 49 def poll result = @buffer[@first] @buffer[@first] = nil @first = (@first + 1) % @buffer.size @count -= 1 result end
Generated with the Darkfish Rdoc Generator 2.