Method: IOReactor#register
- Defined in:
- lib/mega/ioreactor.rb
#register(io, *args, &handler) ⇒ Object Also known as: add
Register the specified IO object with the reactor for events given as args. The reactor will test the given io for the events specified whenever #poll is called. See the #poll method for a list of valid events. If no events are specified, only :error events will be polled for.
If a handler is specified, it will be called whenever the io has any of the specified events occur to it. It should take at least two parameters: the io and the event.
If args contains any objects except the Symbols ‘:read’, ‘:write’, or ‘:error’, and a handler is specified, they will be saved and passed to handler for each event.
Registering a handle will unregister any previously registered event/handler+arguments pairs associated with the handle.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/mega/ioreactor.rb', line 144 def register( io, *args, &handler ) events = [:read, :write, :error] & args args -= events self.unregister( io ) self.enableEvents( io, *events ) if handler self.setHandler( io, *args, &handler ) else self.setArgs( io, *args ) end return self end |