Created
June 18, 2015 10:21
-
-
Save stochastic-thread/5e2c731b432baeb0e60c to your computer and use it in GitHub Desktop.
hello fetch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@arthurcolle call loop at the end of the
loop/1
function and not inside the receive block.