Class: Realm::MultiWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/realm/multi_worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(workers = []) ⇒ MultiWorker

Returns a new instance of MultiWorker.



5
6
7
# File 'lib/realm/multi_worker.rb', line 5

def initialize(workers = [])
  @workers = workers
end

Instance Method Details

#joinObject



18
19
20
# File 'lib/realm/multi_worker.rb', line 18

def join
  @workers.each(&:join)
end

#runObject



22
23
24
25
26
27
28
# File 'lib/realm/multi_worker.rb', line 22

def run
  %w[INT TERM].each do |signal|
    Signal.trap(signal) { stop }
  end
  start
  join
end

#start(*args) ⇒ Object



9
10
11
12
# File 'lib/realm/multi_worker.rb', line 9

def start(*args)
  @workers.each { |w| w.start(*args) }
  self
end

#stop(timeout: 30) ⇒ Object



14
15
16
# File 'lib/realm/multi_worker.rb', line 14

def stop(timeout: 30)
  @workers.each { |w| w.stop(timeout: timeout) }
end