Skip to content

Commit

Permalink
Use Supervisor.child_spec/2 to remove deprecation in Eternal for Elix…
Browse files Browse the repository at this point in the history
…ir 1.11
  • Loading branch information
kipcole9 committed Aug 30, 2020
1 parent 4688196 commit 2babe67
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Changelog for Cldr_Currencies v2.6.2

This is the changelog for Cldr_Currencies v2.6.2 released on August 31st, 2020. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/cldr_currencies/tags)

### Bug Fixes

* Uses `Supervisor.child_spec/2` for `eternal` workers to remove deprecation warning on Elixir 1.11

# Changelog for Cldr_Currencies v2.6.1

This is the changelog for Cldr_Currencies v2.6.1 released on July 19th, 2020. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/cldr_currencies/tags)
Expand Down
30 changes: 13 additions & 17 deletions lib/cldr/eternal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ defmodule Cldr.Eternal do
## Examples
iex> Eternal.start_link(:table1)
{ :ok, _pid1 }
iex> Cldr.Eternal.start_link(:table1, [ ], [ quiet: true ])
iex> Eternal.start_link(:table2, [ :compressed ])
{ :ok, _pid2 }
iex> Cldr.Eternal.start_link(:table2, [ :compressed ], [ quiet: true ])
iex> Eternal.start_link(:table3, [ ], [ quiet: true ])
{ :ok, _pid3 }
iex> Cldr.Eternal.start_link(:table3, [ ], [ quiet: true ])
"""
# @spec start_link(name :: atom, ets_opts :: Keyword.t, opts :: Keyword.t) :: on_start
@dialyzer {:nowarn_function, {:start_link, 3}}
def start_link(name, ets_opts \\ [], opts \\ []) when is_opts(name, ets_opts, opts) do
with { :ok, pid, _table } <- create(name, [ :named_table ] ++ ets_opts, opts) do
{:ok, pid}
Expand All @@ -71,17 +69,15 @@ defmodule Cldr.Eternal do
## Examples
iex> Eternal.start(:table1)
{ :ok, _pid1 }
iex> Cldr.Eternal.start(:table1, [ ], [ quiet: true ])
iex> Eternal.start(:table2, [ :compressed ])
{ :ok, _pid2 }
iex> Cldr.Eternal.start(:table2, [ :compressed ], [ quiet: true ])
iex> Eternal.start(:table3, [ ], [ quiet: true ])
{ :ok, _pid3 }
iex> Cldr.Eternal.start(:table3, [ ], [ quiet: true ])
"""
# @spec start(name :: atom, ets_opts :: Keyword.t, opts :: Keyword.t) :: on_start
@dialyzer {:nowarn_function, {:start, 3}}
def start(name, ets_opts \\ [], opts \\ []) when is_opts(name, ets_opts, opts) do
with {:ok, pid} <- start_link(name, ets_opts, opts) do
:erlang.unlink(pid)
Expand All @@ -94,8 +90,7 @@ defmodule Cldr.Eternal do
## Examples
iex> Eternal.heir(:my_table)
#PID<0.134.0>
iex> Cldr.Eternal.heir(:my_table)
"""
@spec heir(table :: Table.t) :: any()
Expand All @@ -107,8 +102,7 @@ defmodule Cldr.Eternal do
## Examples
iex> Eternal.owner(:my_table)
#PID<0.132.0>
iex> Cldr.Eternal.owner(:my_table)
"""
@spec owner(table :: Table.t) :: any()
Expand All @@ -122,7 +116,7 @@ defmodule Cldr.Eternal do
## Examples
iex> Eternal.stop(:my_table)
iex> Cldr.Eternal.stop(:my_table)
:ok
"""
Expand All @@ -141,6 +135,7 @@ defmodule Cldr.Eternal do
# Creates a table supervisor with the provided options and nominates the children
# as owner/heir of the ETS table immediately afterwards. We do this by fetching
# the children of the supervisor and using the process id to nominate.
@dialyzer {:nowarn_function, {:create, 3}}
defp create(name, ets_opts, opts) do
with { :ok, pid, table } <- Sup.start_link(name, ets_opts, opts),
[proc1, proc2] = Supervisor.which_children(pid),
Expand All @@ -158,6 +153,7 @@ defmodule Cldr.Eternal do
# Callback function when the :ets table
# is created and the supervisor process
# is up and running.
@dialyzer {:nowarn_function, {:maybe_process_callback, 3}}
defp maybe_process_callback(nil, _pid, _table) do
nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/eternal/priv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule Cldr.Eternal.Priv do
@spec log(msg :: any, opts :: Keyword.t) :: :ok
def log(msg, opts) when is_list(opts) do
noisy(opts, fn ->
Logger.debug("[eternal] #{msg}")
Logger.debug(fn -> "[eternal] #{msg}" end)
end)
end

Expand Down
5 changes: 3 additions & 2 deletions lib/cldr/eternal/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule Cldr.Eternal.Supervisor do
# @spec start_link(name :: atom, ets_opts :: Keyword.t, opts :: Keyword.t) ::
# { :ok, pid, Table.t } | :ignore |
# { :error, { :already_started, pid } | { :shutdown, term } | term }
@dialyzer {:nowarn_function, {:start_link, 3}}
def start_link(name, ets_opts \\ [], opts \\ []) when is_opts(name, ets_opts, opts) do
detect_clash(name, ets_opts, fn ->
super_tab = :ets.new(name, [ :public ] ++ ets_opts)
Expand Down Expand Up @@ -53,8 +54,8 @@ defmodule Cldr.Eternal.Supervisor do
end)

children = [
worker(Cldr.Eternal.Server, [{ table, flags, base }], id: Server.One),
worker(Cldr.Eternal.Server, [{ table, flags, base }], id: Server.Two)
Supervisor.child_spec({Cldr.Eternal.Server, { table, flags, base }}, id: Server.One),
Supervisor.child_spec({Cldr.Eternal.Server, { table, flags, base }}, id: Server.Two)
]

Supervisor.init(children, strategy: :one_for_one)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Cldr.Currencies.MixProject do
use Mix.Project

@version "2.6.1"
@version "2.6.2"

def project do
[
Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"earmark": {:hex, :earmark, "1.4.9", "837e4c1c5302b3135e9955f2bbf52c6c52e950c383983942b68b03909356c0d9", [:mix], [{:earmark_parser, ">= 1.4.9", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "0d72df7d13a3dc8422882bed5263fdec5a773f56f7baeb02379361cb9e5b0d8e"},
"earmark_parser": {:hex, :earmark_parser, "1.4.9", "819bda2049e6ee1365424e4ced1ba65806eacf0d2867415f19f3f80047f8037b", [:mix], [], "hexpm", "8bf54fddabf2d7e137a0c22660e71b49d5a0a82d1fb05b5af62f2761cd6485c4"},
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"eternal": {:hex, :eternal, "1.2.1", "d5b6b2499ba876c57be2581b5b999ee9bdf861c647401066d3eeed111d096bc4", [:mix], [], "hexpm", "b14f1dc204321429479c569cfbe8fb287541184ed040956c8862cb7a677b8406"},
"ex_cldr": {:hex, :ex_cldr, "2.16.1", "905b03c38b5fb51668a347f2e6b586bcb2c0816cd98f7d913104872c43cbc61f", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:cldr_utils, "~> 2.9", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "006e500769982e57e6f3e32cbc4664345f78b014bb5ff48ddc394d67c86c1a8d"},
"ex_doc": {:hex, :ex_doc, "0.22.1", "9bb6d51508778193a4ea90fa16eac47f8b67934f33f8271d5e1edec2dc0eee4c", [:mix], [{:earmark, "~> 1.4.0", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "d957de1b75cb9f78d3ee17820733dc4460114d8b1e11f7ee4fd6546e69b1db60"},
"ex_cldr": {:hex, :ex_cldr, "2.16.2", "75e344eaeae7c6943cce84220efd45d52e84f907400234f11d2cf0471d00080a", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:cldr_utils, "~> 2.9", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "04d71af6248d34207eeb4d1b6628848b18e9dbb7c05411d956e930b4a186c746"},
"ex_doc": {:hex, :ex_doc, "0.22.2", "03a2a58bdd2ba0d83d004507c4ee113b9c521956938298eba16e55cc4aba4a6c", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "cf60e1b3e2efe317095b6bb79651f83a2c1b3edcb4d319c421d7fcda8b3aff26"},
"jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"},
"makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"},
Expand Down
2 changes: 2 additions & 0 deletions test/cldr_eteneral_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Cldr.Cldr.EternalTest do

import ExUnit.CaptureLog

doctest Cldr.Eternal

test "starting a table successfully" do
assert(match?({ :ok, _pid }, Cldr.Eternal.start_link(:table_no_options, [], [ quiet: true ])))
end
Expand Down

0 comments on commit 2babe67

Please sign in to comment.