Skip to content

Instantly share code, notes, and snippets.

@jinzhu
Created August 29, 2009 04:45
Show Gist options
  • Save jinzhu/177389 to your computer and use it in GitHub Desktop.
Save jinzhu/177389 to your computer and use it in GitHub Desktop.
-module('area').
-export([start/0,area/2]).
start() -> spawn(fun loop/0).
area(Pid,What) -> rpc(Pid,What).
rpc(Pid,Request) ->
Pid ! {self(),Request},
receive
{Pid,Response} -> Response
end.
loop() ->
receive
{From,{rectangle,Width,Ht}} ->
From ! {self(),Width*Ht},
loop();
{From,{circle,R}} ->
From ! {self(),3.14159 * R * R},
loop();
{From,Other} ->
From ! {self(),Other},
loop()
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment