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

About this user

Julian Fondren

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

a silly FIFO in Erlang (you should use OTP's queue.erl instead)

   1  
   2  -module(fifo).
   3  -export([new/0, loop/0, push/2, pop/1]).
   4  
   5  new() ->
   6      spawn(?MODULE, loop, []).
   7  
   8  loop() ->
   9      receive
  10          {Pid,pop} ->
  11              Pid ! {self(),receive {push,X} ->
  12                                    X
  13                            end),
  14              loop()
  15      end.
  16  
  17  push(Fifo,X) ->
  18      Fifo ! {push,X},
  19      X.
  20  
  21  pop(Fifo) ->
  22      Fifo ! {self(),pop},
  23      receive {Fifo,X} ->
  24              X
  25      end.
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS