Class: EventCore::UnixSignalSource
- Inherits:
-
PipeSource
- Object
- Source
- PipeSource
- EventCore::UnixSignalSource
- Defined in:
- lib/event_core.rb
Overview
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.
Instance Attribute Summary
Attributes inherited from PipeSource
Instance Method Summary collapse
- #close! ⇒ Object
- #event_factory(event_data) ⇒ Object
-
#initialize(*signals) ⇒ UnixSignalSource
constructor
Give it a list of signals, names or integers, to listen for.
Methods inherited from PipeSource
#closed?, #consume_event_data!, #select_io, #select_type, #write
Methods inherited from Source
#closed?, #consume_event_data!, #notify_trigger, #ready!, #ready?, #select_io, #select_type, #timeout, #trigger
Constructor Details
#initialize(*signals) ⇒ UnixSignalSource
Give it a list of signals, names or integers, to listen for.
289 290 291 292 293 294 295 296 297 |
# 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 |
Instance Method Details
#close! ⇒ Object
304 305 306 307 308 |
# 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) ⇒ Object
299 300 301 302 |
# 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 |