<commit_before>require 'redis'
require 'concurrent'

module Pakyow
  module Realtime
    # Manages channel subscriptions for this application instance's WebSockets.
    #
    # @api private
    class RedisSubscription
      SIGNAL_UNSUBSCRIBE = :unsubscribe

      def initialize
        @redis = ::Redis.new(Config.realtime.redis)
      end

      def subscribe(channels = [])
        channels << signal_channel

        Concurrent::Future.execute {
          @redis.subscribe(*channels) do |on|
            on.message do |channel, msg|
              if channel == signal_channel
                if msg == SIGNAL_UNSUBSCRIBE
                  @redis.unsubscribe
                  return
                end
              end

              msg = JSON.parse(msg)

              if msg.is_a?(Hash)
                msg[:__propagated] = true
              elsif msg.is_a?(Array)<commit_msg>Fix unsubscribe signal<commit_after>require 'redis'
require 'concurrent'

module Pakyow
  module Realtime
    # Manages channel subscriptions for this application instance's WebSockets.
    #
    # @api private
    class RedisSubscription
      SIGNAL_UNSUBSCRIBE = 'unsubscribe'

      def initialize
        @redis = ::Redis.new(Config.realtime.redis)
      end

      def subscribe(channels = [])
        channels << signal_channel

        Concurrent::Future.execute {
          @redis.subscribe(*channels) do |on|
            on.message do |channel, msg|
              if channel == signal_channel
                if msg == SIGNAL_UNSUBSCRIBE
                  @redis.unsubscribe
                  return
                end
              end

              msg = JSON.parse(msg)

              if msg.is_a?(Hash)
                msg[:__propagated] = true
              elsif msg.is_a?(Array)
{'fraction_non_alphanumeric': 0.07679372197309417, 'fraction_numerical': 0.0, 'mean_word_length': 1.708649468892261, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3105735', 'n_tokens_mistral': 505, 'n_tokens_neox': 479, 'n_words': 115}