Last active
January 30, 2019 16:23
-
-
Save TylerPachal/beb94bdecd39f02878d84e6b4bbb03ac to your computer and use it in GitHub Desktop.
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
def init(type) do | |
Logger.info("#{type} - init start") | |
state = %{ | |
type: type, | |
data: nil | |
} | |
# Send a message to ourself to load the data outside of the synchronous | |
# init block | |
self() |> send(:more_init) | |
Logger.info("#{type} - init end") | |
{:ok, state} | |
end | |
# Trigger the HTTP call here, instead of ini the init/1 callback | |
def handle_info(:more_init, state) do | |
data = get_data(state.type) | |
updated_state = Map.put(state, :data, data) | |
{:noreply, updated_state} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment