Skip to content

Instantly share code, notes, and snippets.

@dc0d
Created September 27, 2015 21:40
Show Gist options
  • Save dc0d/a15f904f2bb2fa7cc571 to your computer and use it in GitHub Desktop.
Save dc0d/a15f904f2bb2fa7cc571 to your computer and use it in GitHub Desktop.
-module(name_server1).
-export([init/0, add/2, find/1, handle/2]).
-import(server3, [rpc/2]).
%% client routines
add(Name, Place) -> rpc(name_server, {add, Name, Place}).
find(Name) -> rpc(name_server, {find, Name}).
%% callback routines
init() -> dict:new().
handle({add, Name, Place}, Dict) -> {ok, dict:store(Name, Place, Dict)};
handle({find, Name}, Dict) -> {dict:find(Name, Dict), Dict}.
%% usage
%% 1> server3:start(name_server, name_server1).
%% true
%% 2> name_server1:add(joe, "at home").
%% ok
%% 3> name_server1:add(helen, "at work").
%% ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment