Skip to content

Instantly share code, notes, and snippets.

@gjaldon
Last active October 17, 2015 16:22
Show Gist options
  • Save gjaldon/6e0dfc7700299eaccad4 to your computer and use it in GitHub Desktop.
Save gjaldon/6e0dfc7700299eaccad4 to your computer and use it in GitHub Desktop.
def async_query(pid, statement, params) do
message = {:query, statement, params}
process = GenServer.whereis(pid)
monitor = Process.monitor(process)
from = {self(), monitor}
:ok = Connection.cast(pid, {message, from})
%Task{ref: monitor}
end
def handle_cast({{:query, _, _} = command, {_, monitor} = from}, s) do
:ok = handle_call(command, from, s)
{:no_reply, s}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment