<commit_before>require 'concurrent'

module Peribot
  # This class is used to create processor groups. A group consists of a number
  # of "processors" (tasks) that are run in parallel. A message is sent into
  # the group using the {#accept} method, which dispatches it to all processors
  # simultaneously. All processing occurs asynchronously on background threads.
  #
  # This class is designed and intended for internal use within Peribot. It is
  # not considered public, and the API is not guaranteed to be stable.
  #
  # Peribot uses processor groups for sending messages. New groups are created
  # by creating new instances of this class.
  class ProcessorGroup
    include ErrorHelpers

    # Create a new processor group.
    #
    # @param bot [Peribot::Bot] A Peribot instance
    def initialize(bot)
      @bot = bot
      @tasks = []
    end

    attr_reader :bot, :tasks

    # Register a task with this processor group. The given task will be
    # instantiated and used to process the message. Tasks will only be
    # registered once regardless of how many times this method is called with
    # one.
    #
    # @param task [Class] A class with a #process method taking a message
    def register(task)
      tasks << task unless tasks.include? task
    end

    # Dispatch a message to all tasks registered to this group.
    #
    # @param msg [Hash] The message to process
    # @return [Array<Concurrent::IVar>] An array of promises to wait on
    def accept(msg)
      tasks.map do |task|
        Concurrent::Promise.execute { task.new(bot).process(msg) }
                           .rescue { |e| log_failure error: e, message: msg }
      end
    end
  end
end<commit_msg>Make bot accessor private in ProcessorGroup<commit_after>require 'concurrent'

module Peribot
  # This class is used to create processor groups. A group consists of a number
  # of "processors" (tasks) that are run in parallel. A message is sent into
  # the group using the {#accept} method, which dispatches it to all processors
  # simultaneously. All processing occurs asynchronously on background threads.
  #
  # This class is designed and intended for internal use within Peribot. It is
  # not considered public, and the API is not guaranteed to be stable.
  #
  # Peribot uses processor groups for sending messages. New groups are created
  # by creating new instances of this class.
  class ProcessorGroup
    include ErrorHelpers

    # Create a new processor group.
    #
    # @param bot [Peribot::Bot] A Peribot instance
    def initialize(bot)
      @bot = bot
      @tasks = []
    end

    attr_reader :tasks

    # Register a task with this processor group. The given task will be
    # instantiated and used to process the message. Tasks will only be
    # registered once regardless of how many times this method is called with
    # one.
    #
    # @param task [Class] A class with a #process method taking a message
    def register(task)
      tasks << task unless tasks.include? task
    end

    # Dispatch a message to all tasks registered to this group.
    #
    # @param msg [Hash] The message to process
    # @return [Array<Concurrent::IVar>] An array of promises to wait on
    def accept(msg)
      tasks.map do |task|
        Concurrent::Promise.execute { task.new(bot).process(msg) }
                           .rescue { |e| log_failure error: e, message: msg }
      end
    end

    private

    attr_reader :bot
  end
end
{'fraction_non_alphanumeric': 0.06327650967928344, 'fraction_numerical': 0.0, 'mean_word_length': 2.8127753303964758, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4250096', 'n_tokens_mistral': 938, 'n_tokens_neox': 917, 'n_words': 442}