<commit_before>module Concurrently
  # @private
  # The fiber pool grows dynamically if its internal store of fibers is empty.
  class EventLoop::ProcFiberPool
    # Number of fibers allowed to be created per event loop iteration.
    CREATIONS_PER_ITERATION = 1

    def initialize(event_loop)
      @event_loop = event_loop
      @fibers = []
      @iteration_quota = CREATIONS_PER_ITERATION
    end

    def reset_iteration_quota
      @iteration_quota = CREATIONS_PER_ITERATION
    end

    def take_fiber
      @fibers.pop or begin
        # Creating a new fiber only if we are within the iteration quota
        # encourages reuse of fibers by potentially reusing a fiber that will
        # be returned during the next iteration. This is untested in the suite
        # but has a huge impact on performance.
        if @iteration_quota > 0
          @iteration_quota -= 1
          Proc::Fiber.new self
        else
          wait 0
          take_fiber
        end
      end
    end

    def return(fiber)
      @fibers << fiber
    end
  end
end<commit_msg>made sure evaluations waiting for a fiber to take are resumed ASAP<commit_after>module Concurrently
  # @private
  # The fiber pool grows dynamically if its internal store of fibers is empty.
  class EventLoop::ProcFiberPool
    # Number of fibers allowed to be created per event loop iteration.
    CREATIONS_PER_ITERATION = 1

    def initialize(event_loop)
      @event_loop = event_loop
      @fibers = []
      @iteration_quota = CREATIONS_PER_ITERATION
    end

    def reset_iteration_quota
      @iteration_quota = CREATIONS_PER_ITERATION
    end

    def take_fiber
      @fibers.pop or begin
        # Creating a new fiber only if we are within the iteration quota
        # encourages reuse of fibers by potentially reusing a fiber that will
        # be returned during the next iteration. This is untested in the suite
        # but has a huge impact on performance.
        if @iteration_quota > 0
          @iteration_quota -= 1
          Proc::Fiber.new self
        else
          @event_loop.run_queue.schedule_immediately Concurrently::Evaluation.current
          await_resume!
          take_fiber
        end
      end
    end

    def return(fiber)
      @fibers << fiber
    end
  end
end
{'fraction_non_alphanumeric': 0.04258121158911326, 'fraction_numerical': 0.0030728709394205445, 'mean_word_length': 2.3813056379821957, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6809582', 'n_tokens_mistral': 678, 'n_tokens_neox': 615, 'n_words': 235}