Class: Async::Signals::Controller::State

Inherits:
Object
  • Object
show all
Defined in:
lib/async/signals/controller.rb

Overview

Represents the active handlers for a single process signal.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(previous, handlers = {}.compare_by_identity.freeze, ignored = {}.compare_by_identity.freeze) ⇒ State

Initialize the signal state.



20
21
22
23
24
# File 'lib/async/signals/controller.rb', line 20

def initialize(previous, handlers = {}.compare_by_identity.freeze, ignored = {}.compare_by_identity.freeze)
	@previous = previous
	@handlers = handlers
	@ignored = ignored
end

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.



30
31
32
# File 'lib/async/signals/controller.rb', line 30

def handlers
  @handlers
end

#ignoredObject (readonly)

Returns the value of attribute ignored.



33
34
35
# File 'lib/async/signals/controller.rb', line 33

def ignored
  @ignored
end

#previousObject (readonly)

Returns the value of attribute previous.



27
28
29
# File 'lib/async/signals/controller.rb', line 27

def previous
  @previous
end

#The active handlers for the signal.(activehandlers) ⇒ Object (readonly)



30
# File 'lib/async/signals/controller.rb', line 30

attr :handlers

#The active ignored signals.(activeignoredsignals.) ⇒ Object (readonly)



33
# File 'lib/async/signals/controller.rb', line 33

attr :ignored

Instance Method Details

#add(registration, handler) ⇒ Object

Add a signal handler to this state.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/async/signals/controller.rb', line 39

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

#callbacksObject

The active callable signal handlers.



78
79
80
# File 'lib/async/signals/controller.rb', line 78

def callbacks
	@handlers.values.freeze
end

#empty?Boolean

Whether this state has any active handlers.

Returns:

  • (Boolean)


72
73
74
# File 'lib/async/signals/controller.rb', line 72

def empty?
	@handlers.empty? && @ignored.empty?
end

#remove(registration) ⇒ Object

Remove a signal handler from this state.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/async/signals/controller.rb', line 56

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



27
# File 'lib/async/signals/controller.rb', line 27

attr :previous