<commit_before>module RestSpy
  class PendingRequests
    def initialize
      @requests = {}
      @requests_lock = Mutex.new
    end

    def pending_request(request)
      synchronized {
        requests[request.port] = [] unless requests[request.port]
        requests[request.port] << request
      }
    end

    def completed_request(request)
      synchronized {
        requests[request.port].delete(request)
      }
    end

    def empty?(port)
      synchronized {
        (not requests.include? port) || requests[port].size == 0
      }
    end

    def block_until_pending_requests_completed(port, timeout_sec=15)
      #TODO: Busy waiting is bad. Check for signal possibilities
      Timeout.timeout(timeout_sec) do
        until empty?(port)
          sleep(0.1)
        end
      end
    end

    private
    attr_accessor :requests

    def synchronized(&block)
      @requests_lock.synchronize { block.call }
    end
  end
end<commit_msg>Removed unnecessary debug output<commit_after>module RestSpy
  class PendingRequests
    def initialize
      @requests = {}
      @requests_lock = Mutex.new
    end

    def pending_request(request)
      synchronized {
        requests[request.port] = [] unless requests[request.port]
        requests[request.port] << request
      }
    end

    def completed_request(request)
      synchronized {
        requests[request.port].delete(request)
      }
    end

    def empty?(port)
      puts "Pending requests #{requests[port]}"
      synchronized {
        (not requests.include? port) || requests[port].size == 0
      }
    end

    def block_until_pending_requests_completed(port, timeout_sec=15)
      #TODO: Busy waiting is bad. Check for signal possibilities
      Timeout.timeout(timeout_sec) do
        until empty?(port)
          sleep(0.1)
        end
      end
    end

    private
    attr_accessor :requests

    def synchronized(&block)
      @requests_lock.synchronize { block.call }
    end
  end
end
{'fraction_non_alphanumeric': 0.08329126703685008, 'fraction_numerical': 0.005047955577990914, 'mean_word_length': 2.370748299319728, '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': '2114431', 'n_tokens_mistral': 571, 'n_tokens_neox': 570, 'n_words': 132}