Skip to content

Commit

Permalink
Ensure await_all() errors raise from context process
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicletz committed Sep 23, 2024
1 parent 3828ab6 commit b6b9567
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/diode_client/shell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,19 @@ defmodule DiodeClient.Shell do
Hash.sha3_256(BertExt.encode!(list))
end

defp await_all(promises) do
me = self()

pids =
def await_all(promises) do
refs =
for p <- promises do
spawn_link(fn -> send(me, {self(), p.()}) end)
spawn_monitor(fn -> exit({:result, p.()}) end)
end

for pid <- pids do
for {pid, ref} <- refs do
receive do
{^pid, result} -> result
{:DOWN, ^ref, :process, ^pid, {:result, result}} ->
result

{:DOWN, ^ref, :process, ^pid, reason} ->
raise "promise failed: #{inspect(reason)}"
end
end
end
Expand Down

0 comments on commit b6b9567

Please sign in to comment.