class Elastic::Buffer
Constants
- DEFAULT_SIZE
Attributes
queue[R]
size[R]
Public Class Methods
new(size: DEFAULT_SIZE, &blk)
click to toggle source
# File lib/elastic/buffer.rb, line 7 def initialize(size: DEFAULT_SIZE, &blk) @size = size @callback = blk @queue = [] @lock = Mutex.new end
Public Instance Methods
<<(object)
click to toggle source
# File lib/elastic/buffer.rb, line 14 def <<(object) @lock.synchronize do @queue << object flush! if @queue.size >= size end self end
any?()
click to toggle source
# File lib/elastic/buffer.rb, line 29 def any? @queue.any? end
flush!()
click to toggle source
# File lib/elastic/buffer.rb, line 22 def flush! if @queue.any? @callback.call(@queue) if @callback.is_a? Proc @queue = [] end end