Created
September 27, 2015 21:19
-
-
Save dc0d/365435a6760bb5bc181d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(server1). | |
-export([start/2, rpc/2]). | |
start(Name, Mod) -> | |
register(Name, spawn(fun() -> loop(Name, Mod, Mod:init()) end)). | |
rpc(Name, Request) -> | |
Name ! {self(), Request}, | |
receive | |
{Name, Response} -> Response | |
end. | |
loop(Name, Mod, State) -> | |
receive | |
{From, Request} -> | |
{Response, State1} = Mod:handle(Request, State), | |
From ! {Name, Response}, | |
loop(Name, Mod, State1) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment