Class: Rev::AsyncWatcher
- Defined in:
- lib/rev/async_watcher.rb
Overview
The AsyncWatcher lets you signal another thread to wake up. Its intended use is notifying another thread of events.
Instance Method Summary collapse
-
#initialize ⇒ AsyncWatcher
constructor
A new instance of AsyncWatcher.
-
#on_signal ⇒ Object
Called whenever a signal is received.
-
#signal ⇒ Object
Signal the async watcher.
Methods inherited from IOWatcher
#attach, #detach, #disable, #enable, #on_writable
Methods included from Meta
#event_callback, #watcher_delegate
Methods inherited from Watcher
#attach, #attached?, #detach, #disable, #enable, #enabled?, #evloop
Constructor Details
#initialize ⇒ AsyncWatcher
Returns a new instance of AsyncWatcher.
11 12 13 14 |
# File 'lib/rev/async_watcher.rb', line 11 def initialize @reader, @writer = ::IO.pipe super(@reader) end |
Instance Method Details
#on_signal ⇒ Object
Called whenever a signal is received
24 |
# File 'lib/rev/async_watcher.rb', line 24 def on_signal; end |
#signal ⇒ Object
Signal the async watcher. This call is thread safe.
17 18 19 20 21 |
# File 'lib/rev/async_watcher.rb', line 17 def signal # Write a byte to the pipe. What we write is meaningless, it # merely signals an event has occurred for each byte written. @writer.write "\0" end |