<commit_before>class IOEventLoop
  class Concurrency
    include Comparable

    def initialize(loop, run_queue, opts = {}, &body)
      @loop = loop
      @run_queue = run_queue
      @interval = opts.fetch(:every, false)
      @body = body
      schedule_in opts.fetch(:after, 0)
    end

    attr_reader :loop

    private def fiber
      @fiber ||= Fiber.new do
        begin
          while true
            @body.call

            if @interval
              schedule_at @schedule_time+@interval if @scheduled
              Fiber.yield # go back to the main loop
            else
              break
            end
          end
        rescue Exception => e
          @loop.trigger :error, e
        end
      end
    end

    def schedule_at(schedule_time, schedule_result = nil)<commit_msg>added Concurrency.current<commit_after>class IOEventLoop
  class Concurrency
    REGISTRY = {}

    class << self
      def current
        REGISTRY[Fiber.current]
      end
    end

    include Comparable

    def initialize(loop, run_queue, opts = {}, &body)
      @loop = loop
      @run_queue = run_queue
      @interval = opts.fetch(:every, false)
      @body = body
      schedule_in opts.fetch(:after, 0)
    end

    attr_reader :loop

    private def fiber
      @fiber ||= Fiber.new do
        begin
          REGISTRY[@fiber] = self

          while true
            @body.call

            if @interval
              schedule_at @schedule_time+@interval if @scheduled
              Fiber.yield # go back to the main loop
            else
              break
            end
          end
        rescue Exception => e
          @loop.trigger :error, e
        ensure
          REGISTRY.delete @fiber
        end
      end
    end

    def schedule_at(schedule_time, schedule_result = nil)
{'fraction_non_alphanumeric': 0.06948304613674264, 'fraction_numerical': 0.0011117287381878821, 'mean_word_length': 1.6124818577648767, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7040568', 'n_tokens_mistral': 513, 'n_tokens_neox': 490, 'n_words': 145}