Skip to content

Instantly share code, notes, and snippets.

@TylerPachal
Last active January 30, 2019 16:23
Show Gist options
  • Save TylerPachal/beb94bdecd39f02878d84e6b4bbb03ac to your computer and use it in GitHub Desktop.
Save TylerPachal/beb94bdecd39f02878d84e6b4bbb03ac to your computer and use it in GitHub Desktop.
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