Skip to content

Instantly share code, notes, and snippets.

@jakeprem
Created December 4, 2019 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakeprem/5de1ff0dbc89d42b9ce2818c8200feef to your computer and use it in GitHub Desktop.
Save jakeprem/5de1ff0dbc89d42b9ce2818c8200feef to your computer and use it in GitHub Desktop.
Mailman - Useful process mailbox functions for Elixir
defmodule Mailman do
def get_all, do: do_get_all()
def peek(pid \\ nil) do
{:messages, messages} = :erlang.process_info(pid || self(), :messages)
messages
end
defp do_get_all(msgs \\ []) do
receive do
msg -> do_get_all([msg | msgs])
after
0 -> msgs
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment