Sha256: 7ec85493beeb9b0ac448c6dfe58316f27e73dc95db2dccc86da1ae66e4519a19

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module ActionCable
  module Server
    # Collection class for all the connections that's been established on this specific server. Remember, usually you'll run many cable servers, so
    # you can't use this collection as an full list of all the connections established against your application. Use RemoteConnections for that.
    # As such, this is primarily for internal use.
    module Connections
      BEAT_INTERVAL = 3

      def connections
        @connections ||= []
      end

      def add_connection(connection)
        connections << connection
      end

      def remove_connection(connection)
        connections.delete connection
      end

      # WebSocket connection implementations differ on when they'll mark a connection as stale. We basically never want a connection to go stale, as you
      # then can't rely on being able to receive and send to it. So there's a 3 second heartbeat running on all connections. If the beat fails, we automatically
      # disconnect.
      def setup_heartbeat_timer
        @heartbeat_timer ||= Concurrent::TimerTask.new(execution_interval: BEAT_INTERVAL) do
          Concurrent.global_io_executor.post { connections.map(&:beat) }
        end.tap(&:execute)
      end

      def open_connections_statistics
        connections.map(&:statistics)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
actioncable-5.0.0.beta2 lib/action_cable/server/connections.rb