Class: EventBus::Daemon
- Inherits:
-
Object
- Object
- EventBus::Daemon
- Defined in:
- lib/event_bus/daemon.rb
Constant Summary collapse
- INTERRUPTION_SIGNALS =
%w(TERM INT)
Class Method Summary collapse
Class Method Details
.bind_signals ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/event_bus/daemon.rb', line 17 def self.bind_signals read, write = IO.pipe INTERRUPTION_SIGNALS.each do |signal| Signal.trap(signal) { write.puts(signal) } end begin while io = IO.select([read]) signal = io.first[0].gets.strip raise Interrupt if INTERRUPTION_SIGNALS.include?(signal) end rescue Interrupt stop end end |
.start ⇒ Object
5 6 7 8 9 |
# File 'lib/event_bus/daemon.rb', line 5 def self.start Listeners::Manager.bind_all_listeners bind_signals end |