Class: Async::Signals::Controller::State
- Inherits:
-
Object
- Object
- Async::Signals::Controller::State
- Defined in:
- lib/async/signals/controller.rb
Overview
Represents the active handlers for a single process signal.
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
-
#ignored ⇒ Object
readonly
Returns the value of attribute ignored.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
- #The active handlers for the signal.(activehandlers) ⇒ Object readonly
- #The active ignored signals.(activeignoredsignals.) ⇒ Object readonly
Instance Method Summary collapse
-
#add(registration, handler) ⇒ Object
Add a signal handler to this state.
-
#callbacks ⇒ Object
The active callable signal handlers.
-
#empty? ⇒ Boolean
Whether this state has any active handlers.
-
#initialize(previous, handlers = {}.compare_by_identity.freeze, ignored = {}.compare_by_identity.freeze) ⇒ State
constructor
Initialize the signal state.
-
#remove(registration) ⇒ Object
Remove a signal handler from this state.
- #The signal handler that was installed before this controller took ownership.=(signalhandlerthatwasinstalledbeforethiscontrollertookownership. = (value)) ⇒ Object
Constructor Details
#initialize(previous, handlers = {}.compare_by_identity.freeze, ignored = {}.compare_by_identity.freeze) ⇒ State
Initialize the signal state.
21 22 23 24 25 |
# File 'lib/async/signals/controller.rb', line 21 def initialize(previous, handlers = {}.compare_by_identity.freeze, ignored = {}.compare_by_identity.freeze) @previous = previous @handlers = handlers @ignored = ignored end |
Instance Attribute Details
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
31 32 33 |
# File 'lib/async/signals/controller.rb', line 31 def handlers @handlers end |
#ignored ⇒ Object (readonly)
Returns the value of attribute ignored.
34 35 36 |
# File 'lib/async/signals/controller.rb', line 34 def ignored @ignored end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
28 29 30 |
# File 'lib/async/signals/controller.rb', line 28 def previous @previous end |
#The active handlers for the signal.(activehandlers) ⇒ Object (readonly)
31 |
# File 'lib/async/signals/controller.rb', line 31 attr :handlers |
#The active ignored signals.(activeignoredsignals.) ⇒ Object (readonly)
34 |
# File 'lib/async/signals/controller.rb', line 34 attr :ignored |
Instance Method Details
#add(registration, handler) ⇒ Object
Add a signal handler to this state.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/async/signals/controller.rb', line 40 def add(registration, handler) if handler handlers = @handlers.dup handlers[registration] = handler State.new(@previous, handlers.freeze, @ignored) else ignored = @ignored.dup ignored[registration] = nil State.new(@previous, @handlers, ignored.freeze) end end |
#callbacks ⇒ Object
The active callable signal handlers.
79 80 81 82 83 |
# File 'lib/async/signals/controller.rb', line 79 def callbacks @handlers.map do |registration, handler| [handler, registration.context] end.freeze end |
#empty? ⇒ Boolean
Whether this state has any active handlers.
73 74 75 |
# File 'lib/async/signals/controller.rb', line 73 def empty? @handlers.empty? && @ignored.empty? end |
#remove(registration) ⇒ Object
Remove a signal handler from this state.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/async/signals/controller.rb', line 57 def remove(registration) if @handlers.key?(registration) handlers = @handlers.dup handlers.delete(registration) return State.new(@previous, handlers.freeze, @ignored) else ignored = @ignored.dup ignored.delete(registration) return State.new(@previous, @handlers, ignored.freeze) end end |
#The signal handler that was installed before this controller took ownership.=(signalhandlerthatwasinstalledbeforethiscontrollertookownership. = (value)) ⇒ Object
28 |
# File 'lib/async/signals/controller.rb', line 28 attr :previous |