A buffer with a fixed internal capacity. Items can be put onto the buffer without blocking until the internal capacity is reached. Once the buffer is at capacity, subsequent calls to {put} will block until an item is removed from the buffer, creating spare capacity.
@!macro channel_buffer_next
# File lib/concurrent/channel/buffer/buffered.rb, line 56 def next loop do synchronize do if ns_closed? && ns_empty? return Concurrent::NULL, false elsif !ns_empty? item = buffer.shift return item, true end end Thread.pass end end
@!macro channel_buffer_offer
New items can be put onto the buffer until the number of items in the buffer reaches the {size} value specified during initialization.
# File lib/concurrent/channel/buffer/buffered.rb, line 38 def offer(item) synchronize do if ns_closed? || ns_full? return false else ns_put_onto_buffer(item) return true end end end
@!macro channel_buffer_poll
# File lib/concurrent/channel/buffer/buffered.rb, line 71 def poll synchronize do if ns_empty? Concurrent::NULL else buffer.shift end end end
@!macro channel_buffer_put
New items can be put onto the buffer until the number of items in the buffer reaches the {size} value specified during initialization.
# File lib/concurrent/channel/buffer/buffered.rb, line 19 def put(item) loop do synchronize do if ns_closed? return false elsif !ns_full? ns_put_onto_buffer(item) return true end end Thread.pass end end
Generated with the Darkfish Rdoc Generator 2.