Class | Rev::Watcher |
In: |
lib/rev/watcher.rb
ext/rev/rev_buffer.c |
Parent: | Object |
Watchers are Rev‘s event observers. They contain a set of callback methods prefixed by on_* which fire whenever events occur.
In order for a watcher to fire events it must be attached to a running loop. Every watcher has an attach and detach method to control which loop it‘s associated with.
Watchers also have an enable and disable method. This allows a watcher to temporarily ignore certain events while remaining attached to a given loop. This is good for watchers which need to be toggled on and off.
Define callbacks whose behavior can be changed on-the-fly per instance. This is done by giving a block to the callback method, which is captured as a proc and stored for later. If the method is called without a block, the stored block is executed if present, otherwise it‘s a noop.
Use an alternate watcher with the attach/detach/enable/disable methods if it is presently assigned. This is useful if you are waiting for an event to occur before the current watcher can be used in earnest, such as making an outgoing TCP connection.
Temporarily disable an event watcher which is attached to a loop. This is useful if you wish to toggle event monitoring on and off.