Method: ConcurrentWorker::Worker#initialize

Defined in:
lib/concurrent_worker/worker.rb

#initialize(*args, **options, &work_block) ⇒ Worker

Returns a new instance of Worker.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/concurrent_worker/worker.rb', line 22

def initialize(*args, **options, &work_block)
  @args = args
  @options = options
  set_block(:work_block, &work_block) if work_block
  
  @state = :idle
  @result_callbacks = []
  @retired_callbacks = []

  @snd_queue_max = @options[:snd_queue_max] || 2
  @req_mutex   = Mutex.new
  @req_counter = RequestCounter.new
  @options[:result_callback_interrupt]  ||= :immediate 
  @options[:retired_callback_interrupt] ||= :immediate
  @undone_requests = []

  case @options[:type]
  when :process
    class << self
      include ConcurrentProcess
    end
  when :thread
    class << self
      include ConcurrentThread
    end
  else
    class << self
      include ConcurrentThread
    end
  end
end