Skip to content

Instantly share code, notes, and snippets.

@fishcakez
Forked from gjaldon/async_query.ex
Created October 17, 2015 16:22
Show Gist options
  • Save fishcakez/0a466fb8c99fc1b44c2a to your computer and use it in GitHub Desktop.
Save fishcakez/0a466fb8c99fc1b44c2a 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
handle_call(command, from, s)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment