Never been to DZone Snippets before?

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) (See related posts)

-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.

You need to create an account or log in to post comments to this site.


Click here to browse all 5059 code snippets

Related Posts