<commit_before>require 'acfs/service/middleware'

module Acfs

  class Runner
    include Service::Middleware
    attr_reader :adapter

    def initialize(adapter)
      @adapter = adapter
      @running = false
    end

    # Process an operation. Synchronous operations will be run
    # and parallel operations will be queued.
    #
    def process(op)
      op.synchronous? ? run(op) : enqueue(op)
    end

    # Run operation right now skipping queue.
    #
    def run(op)
      adapter.run op_request op
    end

    # List of current queued operations.
    #
    def queue
      @queue ||= []
    end

    # Enqueue operation to be run later.
    #
    def enqueue(op)
      if running?
        adapter.queue op_request op
      else
        queue.append op
        op
        op
      end
    end

    # Return true if queued operations are currently processed.
    #
    def running?
      @running
    end

    # Start processing queued operations.
    #
    def start
      enqueue_operations

      @running = true
      adapter.start
      @running = false
    end

    def clear
      queue.clear
      adapter.abort
    end

    private
    def enqueue_operations
      while (op = queue.shift)
        adapter.queue op_request op
      end
    end

    def op_request(op)
      prepare op.service.prepare op.request
    end
  end
end
<commit_msg>Replace #append with #<< to avoid because it's Ruby 2.0 only.<commit_after>require 'acfs/service/middleware'

module Acfs

  class Runner
    include Service::Middleware
    attr_reader :adapter

    def initialize(adapter)
      @adapter = adapter
      @running = false
    end

    # Process an operation. Synchronous operations will be run
    # and parallel operations will be queued.
    #
    def process(op)
      op.synchronous? ? run(op) : enqueue(op)
    end

    # Run operation right now skipping queue.
    #
    def run(op)
      adapter.run op_request op
    end

    # List of current queued operations.
    #
    def queue
      @queue ||= []
    end

    # Enqueue operation to be run later.
    #
    def enqueue(op)
      if running?
        adapter.queue op_request op
      else
        queue << op
      end
    end

    # Return true if queued operations are currently processed.
    #
    def running?
      @running
    end

    # Start processing queued operations.
    #
    def start
      enqueue_operations

      @running = true
      adapter.start
      @running = false
    end

    def clear
      queue.clear
      adapter.abort
    end

    private
    def enqueue_operations
      while (op = queue.shift)
        adapter.queue op_request op
      end
    end

    def op_request(op)
      return if Acfs::Stub.stubbed(op)
      prepare op.service.prepare op.request
    end
  end
end

{'fraction_non_alphanumeric': 0.061356297093649086, 'fraction_numerical': 0.0007176175098672408, 'mean_word_length': 1.8951194184839044, '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': '2439724', 'n_tokens_mistral': 825, 'n_tokens_neox': 802, 'n_words': 264}