Skip to content

Instantly share code, notes, and snippets.

@rfc1459
Created March 23, 2013 21:47
Show Gist options
  • Select an option

  • Save rfc1459/5229487 to your computer and use it in GitHub Desktop.

Select an option

Save rfc1459/5229487 to your computer and use it in GitHub Desktop.
Stacker server example rewritten using GenX
defmodule Stacker.Server do
import GenX.GenServer
use GenServer.Behaviour
def start_link(stack) do
:gen_server.start_link({:local, Stacker.Server}, __MODULE__, stack, [])
end
def init(stack) do
{ :ok, stack }
end
defcall pop, export: Stacker.Server, state: [h|stack] do
{ :reply, h, stack }
end
defcast push(a), export: Stacker.Server, state: stack do
{ :noreply, [a|stack] }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment