# File lib/facet/io-reactor.rb, line 277
    def poll( timeout=-1 ) # :yields: io, eventMask
        timeout = timeout.to_f
        @pendingEvents.clear
        count = 0

        unless @handles.empty?
            timeout = nil if timeout < 0
            eventedHandles = self.getPendingEvents( timeout )

            # For each event of each io that had an event happen, call any
            # associated callback, or any provided block, or failing both of
            # those, add the event to the hash of unhandled pending events.
            eventedHandles.each {|io,events|
                count += 1
                events.each {|ev|
                    args = @handles[ io ][:args]

                    if @handles[ io ][:handler]
                        @handles[ io ][:handler].call( io, ev, *args )
                    elsif block_given?
                        yield( io, ev, *args )
                    else
                        @pendingEvents[io].push( ev )
                    end
                }
            }
        end

        return count
    end