<commit_before>require 'stackbuilder/support/namespace'

module Support::Forking
  class Future
    def initialize(&block)
      @block = block
    end

    def value
      @block.call
    end
  end

  def async_fork_and_return(&block)
    read, write = IO.pipe
    pid = fork do
      begin
        result = nil
        exception = nil
        result = block.call
      rescue StandardError => e
        exception = e
      end
      Marshal.dump({ :result => result, :exception => exception.message }, write)
    end
    write.close

    Future.new do
      serialized_result = read.read
      Process.waitpid(pid)
      result = Marshal.load(serialized_result)
      fail result[:exception] unless result[:exception].nil?
      result[:result]
    end
  end
end<commit_msg>tomd: only get the message when we have an exception :derp:<commit_after>require 'stackbuilder/support/namespace'

module Support::Forking
  class Future
    def initialize(&block)
      @block = block
    end

    def value
      @block.call
    end
  end

  def async_fork_and_return(&block)
    read, write = IO.pipe
    pid = fork do
      begin
        result = nil
        exception = nil
        result = block.call
      rescue StandardError => e
        exception = e.message
      end
      Marshal.dump({ :result => result, :exception => exception }, write)
    end
    write.close

    Future.new do
      serialized_result = read.read
      Process.waitpid(pid)
      result = Marshal.load(serialized_result)
      fail result[:exception] unless result[:exception].nil?
      result[:result]
    end
  end
end
{'fraction_non_alphanumeric': 0.08448060075093868, 'fraction_numerical': 0.0, 'mean_word_length': 2.324324324324324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3934454', 'n_tokens_mistral': 458, 'n_tokens_neox': 453, 'n_words': 129}