Skip to content

Instantly share code, notes, and snippets.

@stochastic-thread
Created June 18, 2015 10:21
Show Gist options
  • Save stochastic-thread/5e2c731b432baeb0e60c to your computer and use it in GitHub Desktop.
Save stochastic-thread/5e2c731b432baeb0e60c to your computer and use it in GitHub Desktop.
hello fetch
defmodule Life do
def start do
spawn(fn -> loop([]) end)
end
defp loop(list_perm) do
receive do
{:add, url} ->
IO.puts "hey"
resp = HTTPoison.get! url
json_body = Poison.decode! resp.body
list = json_body["data"] |> Enum.map fn(x) -> x["images"]["standard_resolution"]["url"] end
send self(), {:add, json_body["pagination"]}
IO.puts list_perm
loop(list_perm ++ list)
end
end
end
@gjaldon
Copy link

gjaldon commented Jun 19, 2015

@arthurcolle call loop at the end of the loop/1 function and not inside the receive block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment