Class: Vuf::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/vuf/batch.rb

Instance Method Summary collapse

Constructor Details

#initialize(size, &batch) ⇒ Batch

Returns a new instance of Batch.



3
4
5
6
7
8
# File 'lib/vuf/batch.rb', line 3

def initialize(size,&batch)
  @mutex = Mutex.new
  @batchQ = []
  @size = size
  @batch = batch
end

Instance Method Details

#flushObject



16
17
18
19
# File 'lib/vuf/batch.rb', line 16

def flush
  objsToProc = get_objs(0)
  @batch.call(objsToProc)
end

#push(obj) ⇒ Object



10
11
12
13
14
# File 'lib/vuf/batch.rb', line 10

def push(obj)
  @mutex.synchronize { @batchQ << obj }
  objsToProc = get_objs(@size)
  @batch.call(objsToProc) unless objsToProc.nil?
end