Sha256: 0d1d89aeccd13e68e3be8f20ffcac25022a51a53e05b43a7d71f3cfc3ddf4af8

Contents?: true

Size: 618 Bytes

Versions: 3

Compression:

Stored size: 618 Bytes

Contents

module Faye
  module Timeouts
    def add_timeout(name, delay, &block)
      Engine.ensure_reactor_running!
      @timeouts ||= {}
      return if @timeouts.has_key?(name)
      @timeouts[name] = EventMachine.add_timer(delay) do
        @timeouts.delete(name)
        block.call
      end
    end

    def remove_timeout(name)
      @timeouts ||= {}
      timeout = @timeouts[name]
      return if timeout.nil?
      EventMachine.cancel_timer(timeout)
      @timeouts.delete(name)
    end

    def remove_all_timeouts
      @timeouts ||= {}
      @timeouts.keys.each { |name| remove_timeout(name) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faye-1.0.4 lib/faye/mixins/timeouts.rb
faye-1.0.3 lib/faye/mixins/timeouts.rb
faye-1.0.1 lib/faye/mixins/timeouts.rb