Created
August 2, 2010 05:32
-
-
Save alinpopa/504157 to your computer and use it in GitHub Desktop.
This file contains 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
-module(pc_queue). | |
-export([start/0,produce/2,consume/1,status/1]). | |
start() -> | |
Queue = queue:new(), | |
spawn(fun() -> loop(Queue) end). | |
loop(Q) -> | |
receive | |
{produce,Msg} -> | |
io:format("Produce msg: ~p~n",[Msg]), | |
NewQ = queue:in(Msg,Q), | |
loop(NewQ); | |
consume -> | |
case queue:out(Q) of | |
{{value,Msg}, NewQ} -> | |
io:format("Consume msg: ~p~n",[Msg]), | |
loop(NewQ); | |
{empty,_} -> | |
io:format(" -> no msg in queue~n"), | |
loop(Q) | |
end; | |
status -> | |
io:format("QUEUE: ~p~n",[Q]), | |
loop(Q); | |
Command -> | |
io:format(" -> ERROR: invalid command: ~p~n",[Command]), | |
loop(Q) | |
end. | |
produce(QPid, Msg) -> | |
QPid ! {produce, Msg}. | |
consume(QPid) -> | |
QPid ! consume. | |
status(QPid) -> | |
QPid ! status. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment