From 27febafbb479f730515be33af535f0b1945ef051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dawczak?= Date: Tue, 22 May 2018 06:36:50 +0100 Subject: [PATCH 1/2] Change {a->an} before word "app" --- getting-started/mix-otp/supervisor-and-application.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting-started/mix-otp/supervisor-and-application.markdown b/getting-started/mix-otp/supervisor-and-application.markdown index f9c6b9031..3a3ef2e11 100644 --- a/getting-started/mix-otp/supervisor-and-application.markdown +++ b/getting-started/mix-otp/supervisor-and-application.markdown @@ -132,7 +132,7 @@ We can also configure the generated `.app` file by customizing the values return ### Starting applications -When we define a `.app` file, which is the application specification, we are able to start and stop the application as a whole. We haven't worried about this so far for two reasons: +When we define an `.app` file, which is the application specification, we are able to start and stop the application as a whole. We haven't worried about this so far for two reasons: 1. Mix automatically starts our current application for us From af8ca0729a02cf6dbca80db8f7c816fbc22a3a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dawczak?= Date: Tue, 22 May 2018 06:39:54 +0100 Subject: [PATCH 2/2] Format the code (this would be enforced by running `mix format`) --- ...stributed-tasks-and-configuration.markdown | 21 +++++++++--------- .../mix-otp/docs-tests-and-with.markdown | 22 +++++++++---------- .../mix-otp/dynamic-supervisor.markdown | 2 +- getting-started/mix-otp/genserver.markdown | 2 +- .../mix-otp/task-and-gen-tcp.markdown | 6 ++--- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/getting-started/mix-otp/distributed-tasks-and-configuration.markdown b/getting-started/mix-otp/distributed-tasks-and-configuration.markdown index 04afbeed1..46d7c67e4 100644 --- a/getting-started/mix-otp/distributed-tasks-and-configuration.markdown +++ b/getting-started/mix-otp/distributed-tasks-and-configuration.markdown @@ -14,8 +14,10 @@ In this last chapter, we will go back to the `:kv` application and add a routing The routing layer will receive a routing table of the following format: ```elixir -[{?a..?m, :"foo@computer-name"}, - {?n..?z, :"bar@computer-name"}] +[ + {?a..?m, :"foo@computer-name"}, + {?n..?z, :"bar@computer-name"} +] ``` The router will check the first byte of the bucket name against the table and dispatch to the appropriate node based on that. For example, a bucket starting with the letter "a" (`?a` represents the Unicode codepoint of the letter "a") will be dispatched to node `foo@computer-name`. @@ -195,8 +197,7 @@ defmodule KV.Router do """ def table do # Replace computer-name with your local machine name. - [{?a..?m, :"foo@computer-name"}, - {?n..?z, :"bar@computer-name"}] + [{?a..?m, :"foo@computer-name"}, {?n..?z, :"bar@computer-name"}] end end ``` @@ -296,9 +297,11 @@ Open up `apps/kv/mix.exs` and change the `application/0` function to return the ```elixir def application do - [extra_applications: [:logger], - env: [routing_table: []], - mod: {KV, []}] + [ + extra_applications: [:logger], + env: [routing_table: []], + mod: {KV, []} + ] end ``` @@ -336,9 +339,7 @@ This means we can also configure our `:routing_table` directly in the `apps/kv/c ```elixir # Replace computer-name with your local machine nodes. -config :kv, :routing_table, - [{?a..?m, :"foo@computer-name"}, - {?n..?z, :"bar@computer-name"}] +config :kv, :routing_table, [{?a..?m, :"foo@computer-name"}, {?n..?z, :"bar@computer-name"}] ``` Restart the nodes and run distributed tests again. Now they should all pass. diff --git a/getting-started/mix-otp/docs-tests-and-with.markdown b/getting-started/mix-otp/docs-tests-and-with.markdown index 3fcb773f6..7a898ede1 100644 --- a/getting-started/mix-otp/docs-tests-and-with.markdown +++ b/getting-started/mix-otp/docs-tests-and-with.markdown @@ -47,7 +47,7 @@ defmodule KVServer.Command do ## Examples - iex> KVServer.Command.parse "CREATE shopping\r\n" + iex> KVServer.Command.parse("CREATE shopping\r\n") {:ok, {:create, "shopping"}} """ @@ -148,19 +148,19 @@ Notice how we were able to elegantly parse the commands without adding a bunch o Finally, you may have observed that each doctest was considered to be a different test in our test case, as our test suite now reports a total of 7 tests. That is because ExUnit considers the following to define two different tests: ```iex -iex> KVServer.Command.parse "UNKNOWN shopping eggs\r\n" +iex> KVServer.Command.parse("UNKNOWN shopping eggs\r\n") {:error, :unknown_command} -iex> KVServer.Command.parse "GET shopping\r\n" +iex> KVServer.Command.parse("GET shopping\r\n") {:error, :unknown_command} ``` Without new lines, as seen below, ExUnit compiles it into a single test: ```iex -iex> KVServer.Command.parse "UNKNOWN shopping eggs\r\n" +iex> KVServer.Command.parse("UNKNOWN shopping eggs\r\n") {:error, :unknown_command} -iex> KVServer.Command.parse "GET shopping\r\n" +iex> KVServer.Command.parse("GET shopping\r\n") {:error, :unknown_command} ``` @@ -301,24 +301,24 @@ def run({:create, bucket}) do end def run({:get, bucket, key}) do - lookup bucket, fn pid -> + lookup(bucket, fn pid -> value = KV.Bucket.get(pid, key) {:ok, "#{value}\r\nOK\r\n"} - end + end) end def run({:put, bucket, key, value}) do - lookup bucket, fn pid -> + lookup(bucket, fn pid -> KV.Bucket.put(pid, key, value) {:ok, "OK\r\n"} - end + end) end def run({:delete, bucket, key}) do - lookup bucket, fn pid -> + lookup(bucket, fn pid -> KV.Bucket.delete(pid, key) {:ok, "OK\r\n"} - end + end) end defp lookup(bucket, callback) do diff --git a/getting-started/mix-otp/dynamic-supervisor.markdown b/getting-started/mix-otp/dynamic-supervisor.markdown index 3a71c6dc3..aa7efabb9 100644 --- a/getting-started/mix-otp/dynamic-supervisor.markdown +++ b/getting-started/mix-otp/dynamic-supervisor.markdown @@ -179,7 +179,7 @@ In the Applications tab, you will see all applications currently running in your Not only that, as you create new buckets on the terminal, you should see new processes spawned in the supervision tree shown in Observer: ```iex -iex> KV.Registry.create KV.Registry, "shopping" +iex> KV.Registry.create(KV.Registry, "shopping") :ok ``` diff --git a/getting-started/mix-otp/genserver.markdown b/getting-started/mix-otp/genserver.markdown index b15ac1f9f..db562e1f8 100644 --- a/getting-started/mix-otp/genserver.markdown +++ b/getting-started/mix-otp/genserver.markdown @@ -211,7 +211,7 @@ Let's reimplement the server callbacks to fix the bug and make the test pass. Fi def init(:ok) do names = %{} - refs = %{} + refs = %{} {:ok, {names, refs}} end diff --git a/getting-started/mix-otp/task-and-gen-tcp.markdown b/getting-started/mix-otp/task-and-gen-tcp.markdown index dcd139bf4..63489a324 100644 --- a/getting-started/mix-otp/task-and-gen-tcp.markdown +++ b/getting-started/mix-otp/task-and-gen-tcp.markdown @@ -35,9 +35,9 @@ defmodule KVServer do # 3. `active: false` - blocks on `:gen_tcp.recv/2` until data is available # 4. `reuseaddr: true` - allows us to reuse the address if the listener crashes # - {:ok, socket} = :gen_tcp.listen(port, - [:binary, packet: :line, active: false, reuseaddr: true]) - Logger.info "Accepting connections on port #{port}" + {:ok, socket} = + :gen_tcp.listen(port, [:binary, packet: :line, active: false, reuseaddr: true]) + Logger.info("Accepting connections on port #{port}") loop_acceptor(socket) end