lib/sigurd/signal_handler.rb in sigurd-0.0.3 vs lib/sigurd/signal_handler.rb in sigurd-0.1.0

- old
+ new

@@ -19,14 +19,19 @@ def run! setup_signals @runner.start loop do - case signal_queue.pop + signal = signal_queue.pop + case signal when *SIGNALS @runner.stop - break + if Sigurd.exit_on_signal + exit 0 + else + raise(SignalException, signal) + end else ready = IO.select([reader, writer]) # drain the self-pipe so it won't be returned again next time reader.read_nonblock(1) if ready[0].include?(reader) @@ -39,12 +44,11 @@ attr_reader :reader, :writer, :signal_queue # https://stackoverflow.com/questions/29568298/run-code-when-signal-is-sent-but-do-not-trap-the-signal-in-ruby def prepend_handler(signal) previous = Signal.trap(signal) do - previous = -> { raise SignalException, signal } unless previous.respond_to?(:call) yield - previous.call + previous.call if previous&.respond_to?(:call) end end # Trap signals using the self-pipe trick. def setup_signals