Make feed refresh request asynchronous
This commit is contained in:
parent
c37bed932f
commit
b63081392c
|
@ -10,7 +10,7 @@ defmodule Frenzy.UpdateFeeds do
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh(pid, feed) do
|
def refresh(pid, feed) do
|
||||||
GenServer.call(pid, {:refresh, feed})
|
GenServer.cast(pid, {:refresh, feed})
|
||||||
end
|
end
|
||||||
|
|
||||||
def init(state) do
|
def init(state) do
|
||||||
|
@ -19,10 +19,9 @@ defmodule Frenzy.UpdateFeeds do
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_call({:refresh, feed}, _from, state) do
|
def handle_cast({:refresh, feed}, state) do
|
||||||
update_feed(feed)
|
update_feed(feed)
|
||||||
new_feed = Feed |> Repo.get(feed.id) |> Repo.preload(:items)
|
{:noreply, state}
|
||||||
{:reply, new_feed, state}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_info(:update_feeds, state) do
|
def handle_info(:update_feeds, state) do
|
||||||
|
|
|
@ -110,7 +110,7 @@ defmodule FrenzyWeb.FeedController do
|
||||||
|
|
||||||
def refresh(conn, _params) do
|
def refresh(conn, _params) do
|
||||||
feed = conn.assigns[:feed]
|
feed = conn.assigns[:feed]
|
||||||
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
|
Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Refreshing feed. Wait a moment before reloading...")
|
|> put_flash(:info, "Refreshing feed. Wait a moment before reloading...")
|
||||||
|
|
Loading…
Reference in New Issue