<commit_before><commit_msg>Playing with spawn_monitor.<commit_after>defmodule Exercise5 do
  import :timer, only: [ sleep: 1 ]

  def sad_function(parent) do
    send parent, "BOOM!"
    #raise "Boom Exception"
    exit(:boom)
  end

  def receive_messages do
    receive do
      message ->
        IO.puts "Got #{inspect message}"
    after 500 ->
        IO.puts "It seems there's nothing more to do."
        exit :ok
    end
    receive_messages
  end

  def run do
    Process.flag(:trap_exit, true)
    spawn_monitor(Exercise5, :sad_function, [self])
    sleep 500
    receive_messages
  end
end

Exercise5.run
{'fraction_non_alphanumeric': 0.08752025931928688, 'fraction_numerical': 0.01620745542949757, 'mean_word_length': 2.768292682926829, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5205612', 'n_tokens_mistral': 213, 'n_tokens_neox': 199, 'n_words': 60}