`

concurrent-11.19

 
阅读更多
-module(server1).
-export([loop/0, rpc/2]).
rpc(Pid, Request)->
    Pid ! {self(), Request},
    receive
	{Pid, Response}->
	    Response
end.
loop()->
    receive
	{From, {re, W, H}}->
	    From ! {self(), W*H},
	    loop();
	{From, {c, R}} ->
	    From ! {self(), R*R},
	    loop();
	{From, Other} ->
	    From ! {self(), {error, Other}},
	    loop()
end.

result:

27> Pid5 = spawn(fun server1:loop/0).
<0.123.0>
28> server1:rpc(Pid5, {c, 2.0}).
4.0
 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics