class Coolio::AsyncWatcher

The AsyncWatcher lets you signal another thread to wake up. Its intended use is notifying another thread of events.

Public Class Methods

new() click to toggle source
Calls superclass method Coolio::IOWatcher::new
# File lib/cool.io/async_watcher.rb, line 11
def initialize
  @reader, @writer = ::IO.pipe
  super(@reader)
end

Public Instance Methods

on_signal() click to toggle source

Called whenever a signal is received

# File lib/cool.io/async_watcher.rb, line 24
def on_signal; end
signal() click to toggle source

Signal the async watcher. This call is thread safe.

# 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

Protected Instance Methods

on_readable() click to toggle source
# File lib/cool.io/async_watcher.rb, line 31
def on_readable
  # Read a byte from the pipe.  This clears readability, unless
  # another signal is pending
  begin
    @reader.read_nonblock 1
  rescue Errno::EAGAIN
    # in case there are spurious wakeups from forked processs
    return
  end
  on_signal
end