Created
December 4, 2019 15:47
-
-
Save jakeprem/5de1ff0dbc89d42b9ce2818c8200feef to your computer and use it in GitHub Desktop.
Mailman - Useful process mailbox functions for Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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