Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: b2df22a948
Fetching contributors…

Cannot retrieve contributors at this time

40 lines (30 sloc) 0.762 kb
-module(statsderl).
-export([start_link/0, increment/3, called/0, stop/0]).
start_link() ->
spawn_link(fun() -> init() end).
increment(Key, Data, Freq) ->
call({incr, Key, Data, Freq}).
called() -> call(called).
stop() -> call(stop).
init() ->
register(?MODULE, self()),
loop([]).
loop(Stack) ->
receive
{From, {incr, K, D, F}} ->
reply(From, ok),
loop([{K,D,F}|Stack]);
{From, called} ->
reply(From, lists:reverse(Stack)),
loop([]);
{From, stop} ->
reply(From, ok)
end.
call(Msg) ->
Ref = make_ref(),
?MODULE ! {{self(), Ref}, Msg},
receive
{Ref, Reply} -> Reply
end.
reply({Pid, Ref}, Reply) ->
Pid ! {Ref, Reply}.
Jump to Line
Something went wrong with that request. Please try again.