Sha256: f1789785679aa34f38c50fab586c1edbb1423d958e9474585c6216f659083e06

Contents?: true

Size: 1.25 KB

Versions: 16

Compression:

Stored size: 1.25 KB

Contents

module Faye
  module Engine

    class Connection
      include Deferrable
      include Timeouts

      attr_accessor :socket

      def initialize(engine, id, options = {})
        @engine  = engine
        @id      = id
        @options = options
        @inbox   = Set.new
      end

      def deliver(message)
        message.delete('clientId')
        return @socket.send(message) if @socket
        return unless @inbox.add?(message)
        begin_delivery_timeout
      end

      def connect(options, &block)
        options = options || {}
        timeout = options['timeout'] ? options['timeout'] / 1000.0 : @engine.timeout

        set_deferred_status(:unknown)
        callback(&block)

        begin_delivery_timeout
        begin_connection_timeout(timeout)
      end

      def flush
        remove_timeout(:connection)
        remove_timeout(:delivery)

        set_deferred_status(:succeeded, @inbox.entries)
        @inbox = []

        @engine.close_connection(@id) unless @socket
      end

    private

      def begin_delivery_timeout
        return if @inbox.empty?
        add_timeout(:delivery, MAX_DELAY) { flush }
      end

      def begin_connection_timeout(timeout)
        add_timeout(:connection, timeout) { flush }
      end
    end

  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
faye-1.4.0 lib/faye/engines/connection.rb
faye-1.3.0 lib/faye/engines/connection.rb
faye-1.2.5 lib/faye/engines/connection.rb
faye-1.1.3 lib/faye/engines/connection.rb
faye-1.2.4 lib/faye/engines/connection.rb
faye-1.2.3 lib/faye/engines/connection.rb
faye-1.2.2 lib/faye/engines/connection.rb
faye-1.2.1 lib/faye/engines/connection.rb
faye-1.2.0 lib/faye/engines/connection.rb
faye-ouvrages-1.1.2.1 lib/faye/engines/connection.rb
faye-ouvrages-1.1.2 lib/faye/engines/connection.rb
faye-1.1.2 lib/faye/engines/connection.rb
faye-1.1.1 lib/faye/engines/connection.rb
faye-1.1.0 lib/faye/engines/connection.rb
faye-huboard-1.0.5 lib/faye/engines/connection.rb
faye-huboard-1.0.4 lib/faye/engines/connection.rb