Class: Cottontail::Consumer::Launcher
- Inherits:
-
Object
- Object
- Cottontail::Consumer::Launcher
- Defined in:
- lib/cottontail/consumer/launcher.rb
Overview
:nodoc:
Constant Summary collapse
- SIGNALS =
[:QUIT, :TERM, :INT]
Instance Method Summary collapse
-
#initialize(consumer) ⇒ Launcher
constructor
A new instance of Launcher.
- #start ⇒ Object
- #stop ⇒ Object
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
#start ⇒ Object
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 |
#stop ⇒ Object
24 25 26 27 |
# File 'lib/cottontail/consumer/launcher.rb', line 24 def stop @launcher.kill if @launcher.respond_to?(:kill) @launcher = nil end |