Skip to content

Commit

Permalink
make grouped detours calls async
Browse files Browse the repository at this point in the history
  • Loading branch information
bfauble committed Feb 18, 2025
1 parent 8040908 commit 37da28c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/skate_web/controllers/detours_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ defmodule SkateWeb.DetoursController do
def detours(conn, _params) do
%{id: user_id} = AuthManager.Plug.current_resource(conn)

detours = %{
active: Detours.detours_for_user(user_id, :active),
draft: Detours.detours_for_user(user_id, :draft),
past: Detours.detours_for_user(user_id, :past)
}
detours =
[:active, :draft, :past]
|> Enum.map(fn status ->
Task.async(fn -> {status, Detours.detours_for_user(user_id, status)} end)
end)
|> Task.await_many()
|> Map.new()

json(conn, %{data: detours})
end
Expand Down

0 comments on commit 37da28c

Please sign in to comment.