Class: CarrotRpc::ServerRunner::Signal
- Inherits:
-
Object
- Object
- CarrotRpc::ServerRunner::Signal
- Defined in:
- lib/carrot_rpc/server_runner/signal.rb
Overview
Stores a signal and allows for it to be waited on
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Attributes.
Instance Method Summary collapse
-
#initialize ⇒ Signal
constructor
A new instance of Signal.
-
#trap ⇒ void
Traps all Signals.
-
#wait ⇒ String
Waits for a signal trapped by #trap to be received.
Constructor Details
#initialize ⇒ Signal
Returns a new instance of Signal.
9 10 11 |
# File 'lib/carrot_rpc/server_runner/signal.rb', line 9 def initialize self.reader, self.writer = IO.pipe end |
Instance Attribute Details
#name ⇒ Object
Attributes
7 8 9 |
# File 'lib/carrot_rpc/server_runner/signal.rb', line 7 def name @name end |
Instance Method Details
#trap ⇒ void
This method returns an undefined value.
Traps all CarrotRpc::ServerRunner::Signals.
20 21 22 23 24 25 26 |
# File 'lib/carrot_rpc/server_runner/signal.rb', line 20 def trap CarrotRpc::ServerRunner::Signals.trap do |name| # @note can't log from a trap context: since Ruby 2.0 traps don't allow mutexes as it could lead to a dead lock, # so `logger.info` here would return "log writing failed. can't be called from trap context" receive(name) end end |
#wait ⇒ String
Waits for a signal trapped by #trap to be received.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/carrot_rpc/server_runner/signal.rb', line 31 def wait loop do # Wait {#receive}. IO.select can wake up read_ready, _write_ready, _error_ready = IO.select([reader]) next unless read_ready.include? reader reader.read_nonblock(1) break name end end |