Method: Proco::Dispatcher#initialize

Defined in:
lib/proco/dispatcher.rb

#initialize(proco, thread_pool, block) ⇒ Dispatcher

Returns a new instance of Dispatcher.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/proco/dispatcher.rb', line 8

def initialize proco, thread_pool, block
  super()

  @logger, interval, qs, batch, batch_size =
    proco.options.values_at :logger, :interval, :queue_size, :batch, :batch_size
  @queue = if batch && batch_size
             Proco::Queue::BatchQueue.new(qs, batch_size, interval)
           elsif batch
             Proco::Queue::MultiQueue.new(qs, interval)
           else
             Proco::Queue::SingleQueue.new(qs, interval)
           end
  @pool  = thread_pool
  @block = block

  spawn do
    future = items = nil
    LPS.interval(interval).while {
      future, items = @queue.take
      future # JRuby bug
    }.loop do
      inner_loop future, items
    end
  end
end