Skip to content

Instantly share code, notes, and snippets.

@pixyj
Created February 8, 2017 13:10
Show Gist options
  • Save pixyj/9b9fa16bd87d0239c9969946906fcb3e to your computer and use it in GitHub Desktop.
Save pixyj/9b9fa16bd87d0239c9969946906fcb3e to your computer and use it in GitHub Desktop.
Pattern matching example
defmodule ExperimentCoordinator do
use GenServer
require Logger
def handle_call({:configure, config}, _from, :not_started) do
Logger.info "Configuring node with parameters: #{inspect config}..."
{:reply, :ok, :ready}
end
def handle_call(:begin_pings, _from, :ready) do
Logger.info "Pinging Peers...."
{:reply, :ok, :pinging}
end
def handle_call(message, from, state) do
Logger.error "Command #{inspect message} is not handled in #{inspect state} state"
{:reply, :error, state}
end
def run do
{:ok, pid} = GenServer.start_link(__MODULE__, :not_started)
GenServer.call(pid, {:configure, [vivaldi_cc: 0.3]})
GenServer.call(pid, :begin_pings)
GenServer.call(pid, :ready)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment