<commit_before>require 'em-websocket'
require 'json'

module StripMem
  class WebSocket
    def initialize(channel)
      @channel = channel
    end

    def run!
      EventMachine::WebSocket.start(:host => 'localhost', :port => 9998) do |ws|
        ws.onopen do
          sid = @channel.subscribe { |msg| ws.send(JSON.generate(msg)) }
          ws.onclose { @channel.unsubscribe(sid) }
        end
      end
    end
  end
end<commit_msg>Send all data on client connection.<commit_after>require 'em-websocket'
require 'json'

module StripMem
  class WebSocket
    def initialize(channel)
      @channel = channel
      @data = []
      @channel.subscribe { |msg| @data << msg }
    end

    def run!
      EventMachine::WebSocket.start(:host => 'localhost', :port => 9998) do |ws|
        ws.onopen do
          @data.each { |msg| ws.send(JSON.generate(msg)) }
          sid = @channel.subscribe { |msg| ws.send(JSON.generate(msg)) }
          ws.onclose { @channel.unsubscribe(sid) }
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12280701754385964, 'fraction_numerical': 0.007797270955165692, 'mean_word_length': 2.446308724832215, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4860285', 'n_tokens_mistral': 339, 'n_tokens_neox': 319, 'n_words': 80}