Class: Cottontail::Consumer::Launcher

Inherits:
Object
  • Object
show all
Defined in:
lib/cottontail/consumer/launcher.rb

Overview

:nodoc:

Constant Summary collapse

SIGNALS =
[:QUIT, :TERM, :INT]

Instance Method Summary collapse

Constructor Details

#initialize(consumer) ⇒ Launcher

Returns a new instance of Launcher.



8
9
10
11
# File 'lib/cottontail/consumer/launcher.rb', line 8

def initialize(consumer)
  @consumer = consumer
  @launcher = nil
end

Instance Method Details

#startObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/cottontail/consumer/launcher.rb', line 13

def start
  stop unless @launcher.nil?

  SIGNALS.each do |signal|
    Signal.trap(signal) { Thread.new { @consumer.stop } }
  end

  @launcher = Thread.new { sleep }
  @launcher.join
end

#stopObject



24
25
26
27
# File 'lib/cottontail/consumer/launcher.rb', line 24

def stop
  @launcher.kill if @launcher.respond_to?(:kill)
  @launcher = nil
end