<commit_before>require 'io/epoll/epoll'

class IO
  class Epoll
    class Event < Struct.new(:data, :events)
    end

    class << self
      alias create new
    end

    def add(io, events)
      ctl(CTL_ADD, io, events)
    end

    def mod(io, events)
      ctl(CTL_MOD, io, events)
    end

    def del(io)
      ctl(CTL_DEL, io)
    end

    def closed?
      fileno < 0
    end
  end

  def self.epoll(ios, events)
    ios = ios.to_a
    open_len = ios.length
    ep = Epoll.create
    ios.each do |io|
      ep.add(io, events)
    end
    if block_given?
      while 0 < open_len
        evlist = ep.wait
        evlist.each do |ev|
          yield ev
          if ev.events & (Epoll::HUP|Epoll::ERR)
            open_len -= 1
            ev.data.close
          end
        end
      end
      nil
    else
      ep.wait
    end
  end
end<commit_msg>Auto close<commit_after>require 'io/epoll/epoll'

class IO
  class Epoll
    class Event < Struct.new(:data, :events)
    end

    class << self
      alias create new
    end

    def add(io, events)
      ctl(CTL_ADD, io, events)
    end

    def mod(io, events)
      ctl(CTL_MOD, io, events)
    end

    def del(io)
      ctl(CTL_DEL, io)
    end

    def closed?
      fileno < 0
    end
  end

  def self.epoll(ios, events)
    ios = ios.to_a
    open_len = ios.length
    ep = Epoll.create
    ios.each do |io|
      ep.add(io, events)
    end
    if block_given?
      while 0 < open_len
        evlist = ep.wait
        evlist.each do |ev|
          yield ev
          if ev.events & (Epoll::HUP|Epoll::ERR)
            open_len -= 1
            ev.data.close
          end
        end
      end
      ep.close
    else
      evlist = ep.wait
      ep.close
      evlist
    end
  end
end
{'fraction_non_alphanumeric': 0.08708025042686397, 'fraction_numerical': 0.003414911781445646, 'mean_word_length': 1.4971590909090908, 'pattern_counts': {'":': 0, '<': 13, '<?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': '3573366', 'n_tokens_mistral': 652, 'n_tokens_neox': 619, 'n_words': 171}