<commit_before>require 'fiber'

module Pwrake

  class FiberQueue

    def initialize
      @q = []
      @waiter = []
      @finished = false
    end

    def enq(x)
      @q.push(x)
      f = @waiter.shift
      f.resume if f
    end

    def deq
      while @q.empty?
        return nil if @finished
        @waiter.push(Fiber.current)
        Fiber.yield
      end
      return @q.shift
    end

    def finish
      @finished = true
      while f = @waiter.shift
        f.resume
      end
    end

  end
end
<commit_msg>raise FiberQueueError when enq to finished queue<commit_after>require 'fiber'

module Pwrake

  class FiberQueueError < StandardError
  end

  class FiberQueue

    def initialize
      @q = []
      @waiter = []
      @finished = false
    end

    def enq(x)
      if @finished
        raise FiberQueueError,"cannot enq to already finished queue"
      end
      @q.push(x)
      f = @waiter.shift
      f.resume if f
    end

    def deq
      while @q.empty?
        return nil if @finished
        @waiter.push(Fiber.current)
        Fiber.yield
      end
      return @q.shift
    end

    def deq_nonblock
      @q.shift
    end

    def finish
      @finished = true
      while f = @waiter.shift
        f.resume
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.07282693813625685, 'fraction_numerical': 0.0, 'mean_word_length': 1.592292089249493, 'pattern_counts': {'":': 0, '<': 4, '<?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': '646677', 'n_tokens_mistral': 434, 'n_tokens_neox': 415, 'n_words': 120}