aboutsummaryrefslogblamecommitdiffstats
path: root/calc/remote.erl
blob: 793c27cadf9656d776f8d290d386ad3d69d32250 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13



                                
                          







                                      
                                                


                  

                                                  

                    
                             
-module(remote).
-export([start/0, calculate/1]).

rpc(C) ->
    rechner ! {self(), C},
    receive
        {rechner,  Reply} ->
            Reply
    end.

loop() ->
    receive
        {From, {calculate, String}} ->
            From ! {rechner, calc:eval(String)},
            loop()
    end.

start() ->
    register(rechner, spawn(fun() -> loop() end)).

calculate(String) ->
    rpc({calculate, String}).