http://learnyousomeerlang.com/what-is-otp
CraicStack
new()
{:ok, pid}
P
spawn
CraicStack
push(ref, value)
ref
ref :: pid | name
name :: atom()
value :: any()
{:push, value}
P
CraicStack
pop(ref)
value
from :: ref
ref :: pid | name
name :: atom()
value :: any()
{:pop, from}
P
{:pop_reply, value}
CraicStack
peek(ref)
value
ref :: pid | name
name :: atom()
value :: any()
{:peek, from}
P
{:peek_reply, value}
CraicStack
count(ref)
size
ref :: pid | name
name :: atom
size :: positive_integer
{:count, from}
P
{:count_reply, value}
mix new craic_stack
vim craic_stack
STEVEN GOTO VIM NOW...
{:ok, stack} = CraicStack.new
:observer.start
for x <- 1..10_000_000, do: CraicStack.push(stack, x)
for _ <- 1..10_000_000, do: CraicStack.pop(stack)
00:42:13.356 [error] Process #PID<0.95.0> raised an exception
** (MatchError) no match of right hand side value: []
(craic_stack) lib/craic_stack.ex:57: CraicStack.handle/3
(craic_stack) lib/craic_stack.ex:45: CraicStack.loop/1
vim craic_stack
:sys.statistics(stack, :get)
{:ok,
[start_time: {{2017, 1, 31}, {14, 39, 37}},
current_time: {{2017, 1, 31}, {14, 40, 36}},
reductions: 205,
messages_in: 2,
messages_out: 0]}
14:26:25.966 [error] GenServer #PID<0.120.0> terminating
** (MatchError) no match of right hand side value: []
(craic_stack) lib/gen_stack.ex:43: GenStack.handle_call/3
(stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:647: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: :pop
State: %{count: 0, store: []}
Image Credit: High Throughput Erlang - Geoff Cant
defmodule ProblemChild do
use SpecialProcess
def start_link do
SpecialProcess.start_link(__MODULE__, :loop, [])
end
def loop do
IO.puts "Yay I'm looping!"
:timer.sleep(1000)
loop
end
end
https://github.com/rbishop/special_process
holsee.github.com
code: github.com/holsee/craic_stack