Concurrent program template

Posted by stoyan

Something always to start with:
-module(ctemplate).
-compile(export_all).
start() ->
    spawn(fun() -> loop([]) end).

rpc(Pid, Query) ->
    Pid ! {self(), Query},
    receive
        {Pid, Reply} ->
            Reply
    end.

loop(X) ->
    receive
        Any ->
            io:format("Received:~p~n" ,[Any]),
            loop(X)
    end.
Comments

Leave a response