Skip to content

Instantly share code, notes, and snippets.

@nsomar
Created May 17, 2017 13:29
Show Gist options
  • Save nsomar/b5da9bf42508b47a4cd93bee83d1c387 to your computer and use it in GitHub Desktop.
Save nsomar/b5da9bf42508b47a4cd93bee83d1c387 to your computer and use it in GitHub Desktop.
def await(%Task{ref: ref} = task, timeout) do
receive do
{^ref, reply} ->
Process.demonitor(ref, [:flush])
reply
{:DOWN, ^ref, _, proc, reason} ->
exit({reason(reason, proc), {__MODULE__, :await, [task, timeout]}})
after
timeout ->
Process.demonitor(ref, [:flush])
exit({:timeout, {__MODULE__, :await, [task, timeout]}})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment