Class: Proco::Queue::BatchQueue
- Defined in:
- lib/proco/queue/batch_queue.rb
Instance Method Summary collapse
-
#initialize(size, batch_size, delay) ⇒ BatchQueue
constructor
A new instance of BatchQueue.
- #push_impl(item) ⇒ Object
- #take_impl ⇒ Object
Methods inherited from Base
Methods included from MT::Base
#broadcast, #do_when, #signal, #synchronize, #try_when, #wait_until
Constructor Details
#initialize(size, batch_size, delay) ⇒ BatchQueue
Returns a new instance of BatchQueue.
7 8 9 10 11 |
# File 'lib/proco/queue/batch_queue.rb', line 7 def initialize size, batch_size, delay super size, delay @futures = [] @batch_size = batch_size end |
Instance Method Details
#push_impl(item) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/proco/queue/batch_queue.rb', line 13 def push_impl item @items << item if @items.length % @batch_size == 1 @futures << Future.new end @futures.last end |
#take_impl ⇒ Object
21 22 23 24 25 26 |
# File 'lib/proco/queue/batch_queue.rb', line 21 def take_impl items = @items[0, @batch_size] @items = @items[@batch_size..-1] || [] [@futures.shift, items] end |