DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
A Silly FIFO In Erlang (you Should Use OTP's Queue.erl Instead)
-module(fifo).
-export([new/0, loop/0, push/2, pop/1]).
new() ->
spawn(?MODULE, loop, []).
loop() ->
receive
{Pid,pop} ->
Pid ! {self(),receive {push,X} ->
X
end),
loop()
end.
push(Fifo,X) ->
Fifo ! {push,X},
X.
pop(Fifo) ->
Fifo ! {self(),pop},
receive {Fifo,X} ->
X
end.





