Class: Vuf::Batch
- Inherits:
-
Object
- Object
- Vuf::Batch
- Defined in:
- lib/vuf/batch.rb
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(size, &batch) ⇒ Batch
constructor
A new instance of Batch.
- #push(obj) ⇒ Object
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
#flush ⇒ Object
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 |