The AsyncWatcher lets you signal another thread to wake up. Its intended use is notifying another thread of events.
# File lib/cool.io/async_watcher.rb, line 11 def initialize @reader, @writer = ::IO.pipe super(@reader) end
Called whenever a signal is received
# File lib/cool.io/async_watcher.rb, line 24 def on_signal; end
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 "\00"" end
# 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