Class: Coolio::AsyncWatcher

Inherits:
IOWatcher show all
Defined in:
lib/cool.io/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

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

#initializeAsyncWatcher

Returns a new instance of AsyncWatcher.


11
12
13
14
# File 'lib/cool.io/async_watcher.rb', line 11

def initialize
  @reader, @writer = ::IO.pipe
  super(@reader)
end

Instance Method Details

#on_signalObject

Called whenever a signal is received


24
# File 'lib/cool.io/async_watcher.rb', line 24

def on_signal; end

#signalObject

Signal the async watcher. This call is thread safe.


17
18
19
20
21
# File 'lib/cool.io/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