Skip to content

Instantly share code, notes, and snippets.

@enpedasi
Created July 3, 2018 13:12
Show Gist options
  • Save enpedasi/f9794d79a12df0332a22d16b17411cbe to your computer and use it in GitHub Desktop.
Save enpedasi/f9794d79a12df0332a22d16b17411cbe to your computer and use it in GitHub Desktop.
NIF Thread Reciever (GenServer)
defmodule NIFThread.Receiver do
use GenServer
def start_link(init_list\\[]) do
GenServer.start_link(__MODULE__, init_list)
end
def init(list) do
{:ok, list}
end
def handle_call(:get, _from, state) do
{:reply, state, []}
end
def handle_info({:push, new_state}, state) do
# IO.inspect server: new_state
{:noreply, [new_state | state]}
end
def handle_info(:ok, state) do
{:noreply, state}
end
def handle_info({:ok, _new_state}, state) do
{:noreply, state}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment