class EventCore::UnixSignalSource

A source that marshals Unix signals to be handled in the main loop. This detaches you from the dreaded “trap context”, and allows you to reason about the state of the rest of your app in the signal handler.

The trigger is called with an array of signals as argument. There can be more than one signal if more than one signal fired since the source was last checked.

Closing the signal handler will set the trap handler to DEFAULT.

Public Class Methods

new(*signals) click to toggle source

Give it a list of signals, names or integers, to listen for.

Calls superclass method EventCore::PipeSource::new
# File lib/event_core.rb, line 289
def initialize(*signals)
  super()
  @signals = signals
  @signals.each do |sig|
    Signal.trap(sig) do
      write("#{sig}+")
    end
  end
end

Public Instance Methods

close!() click to toggle source
Calls superclass method EventCore::PipeSource#close!
# File lib/event_core.rb, line 304
def close!
  super
  # Restore default signal handlers
  @signals.each { |sig| Signal.trap(sig, "DEFAULT")}
end
event_factory(event_data) click to toggle source
# File lib/event_core.rb, line 299
def event_factory(event_data)
  # We may have received more than one signal since last check
  event_data.split('+')
end