Skip to content

Commit 14ea6a7

Browse files
committed
Simplify TypedGenServer.Stage1.Server not to use GenServer.reply
1 parent a956195 commit 14ea6a7

File tree

1 file changed

+9
-11
lines changed
  • examples/typed_gen_server/lib/typed_gen_server

1 file changed

+9
-11
lines changed

examples/typed_gen_server/lib/typed_gen_server/stage1.ex

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,20 @@ defmodule TypedGenServer.Stage1.Server do
4949
{:ok, state}
5050
end
5151

52-
# @impl true
53-
def handle_call(m, from, state) do
54-
{:noreply, handle(m, from, state)}
55-
end
52+
@type called(a) :: {:noreply, state()}
53+
| {:reply, a, state()}
5654

57-
@spec handle(message(), any, any) :: state()
55+
# @impl true
56+
@spec handle_call(message(), GenServer.from(), state())
57+
:: called(Contract.Echo.res() | Contract.Hello.res())
5858
## Try breaking the pattern match, e.g. by changing 'echo_req'
59-
def handle({:echo_req, payload}, from, state) do
60-
GenServer.reply(from, {:echo_res, payload})
61-
state
59+
def handle_call({:echo_req, payload}, _from, state) do
60+
{:reply, {:echo_res, payload}, state}
6261
end
6362

6463
## Try commenting out the following clause
65-
def handle({:hello, name}, from, state) do
64+
def handle_call({:hello, name}, _from, state) do
6665
IO.puts("Hello, #{name}!")
67-
GenServer.reply(from, :ok)
68-
state
66+
{:reply, :ok, state}
6967
end
7068
end

0 commit comments

Comments
 (0)