Sha256: 2071e742c5fe18ec8c4a2fcfe6ffc6b613ea788f46da3160d0897477746f773a

Contents?: true

Size: 903 Bytes

Versions: 3

Compression:

Stored size: 903 Bytes

Contents

require 'singleton'

module Pakyow
  module Realtime
    # Manages WebSocket connections and their subscriptions in memory.
    #
    # Intended only for use in development or single app-instance deployments.
    #
    # @api private
    class SimpleRegistry
      include Singleton

      def initialize
        @channels = {}
      end

      def channels_for_key(key)
        @channels.fetch(key, [])
      end

      def unregister_key(key)
        @channels.delete(key)
      end

      def subscribe_to_channels_for_key(channels, key)
        @channels[key] ||= []
        @channels[key].concat(Array.ensure(channels.map(&:to_sym))).uniq!
      end

      def unsubscribe_to_channels_for_key(channels, key)
        @channels[key] ||= []
        @channels[key] = @channels[key] - Array.ensure(channels.map(&:to_sym))
      end
      
      def propagates?
        false
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pakyow-realtime-0.10.2 pakyow-realtime/lib/pakyow-realtime/registries/simple_registry.rb
pakyow-realtime-0.10.1 pakyow-realtime/lib/pakyow-realtime/registries/simple_registry.rb
pakyow-realtime-0.10.0 pakyow-realtime/lib/pakyow-realtime/registries/simple_registry.rb