@@ -6,13 +6,13 @@ I won't try to fill in all the details, but I'll build up the structure you can
66## The Simplest Thing That Works
77
88The place to start is with a very simple service: a key-value store.
9- You can set values, you can get values, and that's about it.
9+ You can set values, you can fetch values, and that's about it.
1010We'll use it something like this:
1111
1212``` erlang
1313S = kvstore :start ().
1414kvstore :set (name , " Colin" , S ).
15- V = kvstore :get (name , S ).
15+ V = kvstore :fetch (name , S ).
1616```
1717
1818Behind the scenes, we're spinning off an Erlang process and sending messages to it.
@@ -27,8 +27,8 @@ start() ->
2727set (Key , Value , Pid ) ->
2828 Pid ! {set , Key , Value }.
2929
30- get (Key , Pid ) ->
31- Pid ! {self (), {get , Key }},
30+ fetch (Key , Pid ) ->
31+ Pid ! {self (), {fetch , Key }},
3232 receive Value -> Value end .
3333```
3434
@@ -37,7 +37,7 @@ The `loop` function receives these requests, either updates its data or sends ba
3737``` erlang
3838loop (State ) ->
3939 receive
40- {From , {get , Key }} ->
40+ {From , {fetch , Key }} ->
4141 {ok , Value } = dict :find (Key , State ),
4242 From ! Value ,
4343 loop (State );
@@ -50,7 +50,7 @@ loop(State) ->
5050## Re-plumbing
5151
5252That's it for a basic, functioning service. Now let's mess with it a bit.
53- If we look at the message passing, we see that ` set ` is a one-way request, and ` get ` is a two-way request.
53+ If we look at the message passing, we see that ` set ` is a one-way request, and ` fetch ` is a two-way request.
5454Let's split that logic out a bit.
5555
5656``` erlang
@@ -64,7 +64,7 @@ loop(State) ->
6464 end ,
6565 loop (NewState ).
6666
67- handle_call ({get , Key }, State ) ->
67+ handle_call ({fetch , Key }, State ) ->
6868 {ok , Value } = dict :find (Key , State ),
6969 {State , Value }.
7070
@@ -119,8 +119,8 @@ So now the client functions look like:
119119set (Key , Value , Pid ) ->
120120 cast ({set , Key , Value }, Pid ).
121121
122- get (Key , Pid ) ->
123- call ({get , Key }, Pid ).
122+ fetch (Key , Pid ) ->
123+ call ({fetch , Key }, Pid ).
124124
125125increment (Key , Pid ) ->
126126 call ({increment , Key }, Pid ).
@@ -158,7 +158,7 @@ A set of business logic plugin functions:
158158And a set of custom API functions that hide the message format from the outside world:
159159
160160* ` set/3 `
161- * ` get /2`
161+ * ` fetch /2`
162162* ` increment/2 `
163163
164164They line up sorta like this:
@@ -167,7 +167,7 @@ They line up sorta like this:
167167 <tr ><th > API </th ><th > Generic </th ><th > Plugin </th ></tr >
168168 <tr ><td > </td ><td > start/0 </td ><td > init/1 </td ></tr >
169169 <tr ><td > set/3 </td ><td > cast/2 </td ><td > handle_cast/2 </td ></tr >
170- <tr ><td > get /2 </td ><td rowspan =" 2 " > call/2 </td ><td rowspan =" 2 " > handle_call/2 </td ></tr >
170+ <tr ><td > fetch /2 </td ><td rowspan =" 2 " > call/2 </td ><td rowspan =" 2 " > handle_call/2 </td ></tr >
171171 <tr ><td > increment/2 </td ></tr >
172172 <tr ><td > </td ><td > loop/1 </td ><td > </td ></tr >
173173</table >
0 commit comments