Make feed refresh request asynchronous

This commit is contained in:
Shadowfacts 2020-05-31 16:13:00 -04:00
parent c37bed932f
commit b63081392c
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 4 additions and 5 deletions

View File

@ -10,7 +10,7 @@ defmodule Frenzy.UpdateFeeds do
end
def refresh(pid, feed) do
GenServer.call(pid, {:refresh, feed})
GenServer.cast(pid, {:refresh, feed})
end
def init(state) do
@ -19,10 +19,9 @@ defmodule Frenzy.UpdateFeeds do
{:ok, state}
end
def handle_call({:refresh, feed}, _from, state) do
def handle_cast({:refresh, feed}, state) do
update_feed(feed)
new_feed = Feed |> Repo.get(feed.id) |> Repo.preload(:items)
{:reply, new_feed, state}
{:noreply, state}
end
def handle_info(:update_feeds, state) do

View File

@ -110,7 +110,7 @@ defmodule FrenzyWeb.FeedController do
def refresh(conn, _params) do
feed = conn.assigns[:feed]
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
conn
|> put_flash(:info, "Refreshing feed. Wait a moment before reloading...")