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

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

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.
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS