Skip to content

Commit 49c0c7d

Browse files
committed
Code for step 4
1 parent ad5d6aa commit 49c0c7d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/book_store/application.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ defmodule BookStore.Application do
1313
BookStoreWeb.Telemetry,
1414
# Start the PubSub system
1515
{Phoenix.PubSub, name: BookStore.PubSub},
16+
# Start the Book Store Registry
17+
BookStore.BookRegistry.child_spec(),
1618
# Start the Endpoint (http/https)
1719
BookStoreWeb.Endpoint
1820
# Start a worker by calling: BookStore.Worker.start_link(arg)

lib/book_store/book_registry.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule BookStore.BookRegistry do
2+
def child_spec do
3+
Registry.child_spec(
4+
keys: :unique,
5+
name: __MODULE__,
6+
partitions: System.schedulers_online()
7+
)
8+
end
9+
10+
def lookup_book(book_id) do
11+
case Registry.lookup(__MODULE__, book_id) do
12+
[{book_pid, _}] ->
13+
{:ok, book_pid}
14+
15+
[] ->
16+
{:error, :not_found}
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)