This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmodule coffee | |
(export | |
(tea 0) | |
(espresso 0) | |
(americano 0) | |
(cappuccino 0) | |
(pay 1) | |
(cup-removed 0) | |
(cancel 0) | |
(start_link 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmodule coffee-fsm | |
(behaviour gen_fsm) | |
(export | |
(start-link 0) | |
(stop 0) | |
(handle_sync_event 4) | |
(init 1) | |
(terminate 3) | |
(selection 2) | |
(payment 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmodule my-supervisor | |
(export | |
(start 2) | |
(init 1) | |
(stop 1))) | |
(defun start (name child-spec-list) | |
"Start a supervisor with `name` and `child-spec-list`." | |
(let ((pid (spawn (MODULE) 'init (list child-spec-list)))) | |
(register name pid) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule HLR do | |
@moduledoc""" | |
Maintain the associations between Mobile Subscriber Integrated Services Digital Network (MSISDN) numbers and process | |
identifiers (PID). | |
""" | |
def new() do | |
:ets.new(:msisdn_pid, [:named_table]) | |
:ets.new(:pid_msisdn, [:named_table]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Frequency do | |
@moduledoc""" | |
""" | |
# Client API | |
def start() do | |
Process.register(Process.spawn(&init/0, []), :frequency) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Frequency do | |
use GenServer | |
@moduledoc""" | |
Maintain a list of available radio frequencies and any associations between process identifiers and their | |
allocated frequencies. | |
""" | |
@initial_allocations [] | |
@initial_frequencies [10, 11, 12, 13, 14, 15] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Coffee do | |
use GenStateMachine, callback_mode: :state_functions | |
# Client API | |
def start_link() do | |
GenStateMachine.start_link(__MODULE__, {}, [name: __MODULE__]) | |
end | |
def stop() do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule PhoneFSM do | |
@behaviour :gen_statem | |
@moduledoc """ | |
A mobile 'phone controller. | |
""" | |
# Client API | |
def start_link(ms), do: :gen_statem.start_link(__MODULE__, ms, []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Sup do | |
def start(name, child_spec_list) do | |
Process.register(pid = spawn(__MODULE__, :init, [child_spec_list]), name) | |
{:ok, pid} | |
end | |
def stop(name), do: send(name, :stop) | |
def init(child_spec_list) do |
OlderNewer