Skip to content

Commit 5c86e1c

Browse files
committed
Added a doc. link to the pin op. and corrected the spawn_link output
1 parent f0e787b commit 5c86e1c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

getting-started/mix-otp/genevent.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Let's first change our tests to showcase the behaviour we want the registry to e
102102

103103
In order to test the functionality we want to add, we first define a `Forwarder` (the same one we typed in IEx previously). On `setup`, we start the event manager, pass it as an argument to the registry and add our `Forwarder` handler to the manager so events can be sent to the test process.
104104

105-
In the test, we create and stop a bucket process and use `assert_receive` to assert we will receive both `:create` and `:exit` messages. `assert_receive` has a default timeout of 100ms which should be more than enough for our tests. Also note that `assert_receive` expects a pattern, rather than a value, that's why we have used `^bucket` to match on the bucket pid.
105+
In the test, we create and stop a bucket process and use `assert_receive` to assert we will receive both `:create` and `:exit` messages. `assert_receive` has a default timeout of 100ms which should be more than enough for our tests. Also note that `assert_receive` expects a pattern, rather than a value, that's why we have used `^bucket`, with the [pin operator](/getting-started/pattern-matching.html#the-pin-operator), to match on the bucket pid.
106106

107107
Finally, notice we called `GenEvent.add_mon_handler/3` instead of `GenEvent.add_handler/3`. This function adds a handler, as we know, and also tells the event manager to monitor the current process. If the current process dies, the event handler is automatically removed. This makes sense because, in the `Forwarder` case, we should stop forwarding messages if the recipient of those messages (`self()`/the test process) is no longer alive.
108108

@@ -196,7 +196,7 @@ iex> {:ok, manager} = GenEvent.start_link
196196
iex> spawn_link fn ->
197197
...> for x <- GenEvent.stream(manager), do: IO.inspect(x)
198198
...> end
199-
:ok
199+
#PID<0.97.0>
200200
iex> GenEvent.notify(manager, {:hello, :world})
201201
{:hello, :world}
202202
:ok

0 commit comments

Comments
 (0)