Skip to content

Commit c279bd3

Browse files
author
Colin MacDonald
committed
Renamed 'get' to 'fetch' to avoid confusion.
1 parent 1c61123 commit c279bd3

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

88
The 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.
1010
We'll use it something like this:
1111

1212
```erlang
1313
S = kvstore:start().
1414
kvstore:set(name, "Colin", S).
15-
V = kvstore:get(name, S).
15+
V = kvstore:fetch(name, S).
1616
```
1717

1818
Behind the scenes, we're spinning off an Erlang process and sending messages to it.
@@ -27,8 +27,8 @@ start() ->
2727
set(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
3838
loop(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

5252
That'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.
5454
Let'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:
119119
set(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

125125
increment(Key, Pid) ->
126126
call({increment, Key}, Pid).
@@ -158,7 +158,7 @@ A set of business logic plugin functions:
158158
And 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

164164
They 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>

snippets/kv1.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-module(kv1).
22

3-
-export([start/0, set/3, get/2]).
3+
-export([start/0, set/3, fetch/2]).
44

55
start() ->
66
State = dict:new(),
@@ -10,13 +10,13 @@ start() ->
1010
set(Key, Value, Pid) ->
1111
Pid ! {set, Key, Value}.
1212

13-
get(Key, Pid) ->
14-
Pid ! {self(), {get, Key}},
13+
fetch(Key, Pid) ->
14+
Pid ! {self(), {fetch, Key}},
1515
receive Value -> Value end.
1616

1717
loop(State) ->
1818
receive
19-
{From, {get, Key}} ->
19+
{From, {fetch, Key}} ->
2020
{ok, Value} = dict:find(Key, State),
2121
From ! Value,
2222
loop(State);

snippets/kv2.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-module(kv2).
22

3-
-export([start/0, set/3, get/2, increment/2]).
3+
-export([start/0, set/3, fetch/2, increment/2]).
44

55
start() ->
66
State = dict:new(),
@@ -10,8 +10,8 @@ start() ->
1010
set(Key, Value, Pid) ->
1111
Pid ! {set, Key, Value}.
1212

13-
get(Key, Pid) ->
14-
Pid ! {self(), {get, Key}},
13+
fetch(Key, Pid) ->
14+
Pid ! {self(), {fetch, Key}},
1515
receive Value -> Value end.
1616

1717
increment(Key, Pid) ->
@@ -28,7 +28,7 @@ loop(State) ->
2828
end,
2929
loop(NewState).
3030

31-
handle_call({get, Key}, State) ->
31+
handle_call({fetch, Key}, State) ->
3232
{ok, Value} = dict:find(Key, State),
3333
{State, Value};
3434
handle_call({increment, Key}, State) ->

snippets/kv3.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-module(kv3).
22

3-
-export([start/0, set/3, get/2, increment/2]).
3+
-export([start/0, set/3, fetch/2, increment/2]).
44

55
start() ->
66
State = init(),
@@ -12,8 +12,8 @@ init() -> dict:new().
1212
set(Key, Value, Pid) ->
1313
cast({set, Key, Value}, Pid).
1414

15-
get(Key, Pid) ->
16-
call({get, Key}, Pid).
15+
fetch(Key, Pid) ->
16+
call({fetch, Key}, Pid).
1717

1818
increment(Key, Pid) ->
1919
call({increment, Key}, Pid).
@@ -35,7 +35,7 @@ loop(State) ->
3535
end,
3636
loop(NewState).
3737

38-
handle_call({get, Key}, State) ->
38+
handle_call({fetch, Key}, State) ->
3939
{ok, Value} = dict:find(Key, State),
4040
{State, Value};
4141
handle_call({increment, Key}, State) ->

0 commit comments

Comments
 (0)