From 9035ec0410b6493560ebf3b80aef23b9ae7fa8ff Mon Sep 17 00:00:00 2001 From: Isaac Whitfield Date: Mon, 11 Mar 2024 15:56:16 -0700 Subject: [PATCH] Reapply mix formatting --- lib/cachex.ex | 7 ++----- lib/cachex/actions.ex | 2 +- lib/cachex/actions/put.ex | 2 +- lib/cachex/services/courier.ex | 2 +- lib/cachex/services/locksmith.ex | 4 ++-- lib/cachex/services/locksmith/queue.ex | 4 ++-- lib/cachex/services/overseer.ex | 2 +- lib/cachex/spec.ex | 3 +++ 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/cachex.ex b/lib/cachex.ex index 8ecb525..feb9326 100644 --- a/lib/cachex.ex +++ b/lib/cachex.ex @@ -327,8 +327,7 @@ defmodule Cachex do """ @spec start(atom, Keyword.t()) :: {atom, pid} def start(name, options \\ []) do - with {:ok, pid} <- start_link(name, options), - true <- :erlang.unlink(pid) do + with {:ok, pid} <- start_link(name, options), true <- :erlang.unlink(pid) do {:ok, pid} end end @@ -339,9 +338,7 @@ defmodule Cachex do # This will start all cache services required using the `Cachex.Services` # module and attach them under a Supervisor instance backing the cache. @spec init(cache :: Cachex.Spec.cache()) :: - {:ok, - {Supervisor.sup_flags(), - [Supervisor.child_spec() | (old_erlang_child_spec :: Supervisor.child_spec())]}} + {:ok, {Supervisor.sup_flags(), [Supervisor.child_spec()]}} def init(cache() = cache) do cache |> Services.cache_spec() diff --git a/lib/cachex/actions.ex b/lib/cachex/actions.ex index 1b825da..6d4d6ee 100644 --- a/lib/cachex/actions.ex +++ b/lib/cachex/actions.ex @@ -98,7 +98,7 @@ defmodule Cachex.Actions do @doc """ Writes a new entry into a cache. """ - @spec write(Cachex.Spec.cache(), [Cachex.Spec.entry()]) :: {:ok, boolean} + @spec write(Cachex.Spec.cache(), Cachex.Spec.entries()) :: {:ok, boolean} def write(cache(name: name), entries), do: {:ok, :ets.insert(name, entries)} diff --git a/lib/cachex/actions/put.ex b/lib/cachex/actions/put.ex index 7a12e26..5768cf2 100644 --- a/lib/cachex/actions/put.ex +++ b/lib/cachex/actions/put.ex @@ -32,7 +32,7 @@ defmodule Cachex.Actions.Put do record = entry_now(key: key, ttl: expiry, value: value) Locksmith.write(cache, [key], fn -> - Actions.write(cache, [record]) + Actions.write(cache, record) end) end end diff --git a/lib/cachex/services/courier.ex b/lib/cachex/services/courier.ex index 04ea3a6..bcad3fa 100644 --- a/lib/cachex/services/courier.ex +++ b/lib/cachex/services/courier.ex @@ -39,7 +39,7 @@ defmodule Cachex.Services.Courier do simplify the interfaces internally. This is a blocking remote call which will wait until a result can be loaded. """ - @spec dispatch(Cachex.Spec.cache(), any, (() -> any)) :: any + @spec dispatch(Cachex.Spec.cache(), any, (-> any)) :: any def dispatch(cache() = cache, key, task) when is_function(task, 0), do: service_call(cache, :courier, {:dispatch, key, task, local_stack()}) diff --git a/lib/cachex/services/locksmith.ex b/lib/cachex/services/locksmith.ex index 1072762..0f50822 100644 --- a/lib/cachex/services/locksmith.ex +++ b/lib/cachex/services/locksmith.ex @@ -101,7 +101,7 @@ defmodule Cachex.Services.Locksmith do This is mainly shorthand to avoid having to handle row locking explicitly. """ - @spec transaction(Cachex.Spec.cache(), [any], (() -> any)) :: any + @spec transaction(Cachex.Spec.cache(), [any], (-> any)) :: any def transaction(cache() = cache, keys, fun) when is_list(keys) do case transaction?() do true -> fun.() @@ -155,7 +155,7 @@ defmodule Cachex.Services.Locksmith do transactions executed against it we skip the lock check as any of our ETS writes are atomic and so do not require a lock. """ - @spec write(Cachex.Spec.cache(), any, (() -> any)) :: any + @spec write(Cachex.Spec.cache(), any, (-> any)) :: any def write(cache(transactional: false), _keys, fun), do: fun.() diff --git a/lib/cachex/services/locksmith/queue.ex b/lib/cachex/services/locksmith/queue.ex index df2cf92..91c5e82 100644 --- a/lib/cachex/services/locksmith/queue.ex +++ b/lib/cachex/services/locksmith/queue.ex @@ -30,14 +30,14 @@ defmodule Cachex.Services.Locksmith.Queue do @doc """ Executes a function in a lock-free context. """ - @spec execute(Cachex.Spec.cache(), (() -> any)) :: any + @spec execute(Cachex.Spec.cache(), (-> any)) :: any def execute(cache() = cache, func) when is_function(func, 0), do: service_call(cache, :locksmith, {:exec, func}) @doc """ Executes a function in a transactional context. """ - @spec transaction(Cachex.Spec.cache(), [any], (() -> any)) :: any + @spec transaction(Cachex.Spec.cache(), [any], (-> any)) :: any def transaction(cache() = cache, keys, func) when is_list(keys) and is_function(func, 0), do: service_call(cache, :locksmith, {:transaction, keys, func}) diff --git a/lib/cachex/services/overseer.ex b/lib/cachex/services/overseer.ex index 365fc00..35b4557 100644 --- a/lib/cachex/services/overseer.ex +++ b/lib/cachex/services/overseer.ex @@ -106,7 +106,7 @@ defmodule Cachex.Services.Overseer do @doc """ Carries out a transaction against the state table. """ - @spec transaction(atom, (() -> any)) :: any + @spec transaction(atom, (-> any)) :: any def transaction(name, fun) when is_atom(name) and is_function(fun, 0), do: :sleeplocks.execute(@manager_name, fun) diff --git a/lib/cachex/spec.ex b/lib/cachex/spec.ex index 6e01b10..11f51f3 100644 --- a/lib/cachex/spec.ex +++ b/lib/cachex/spec.ex @@ -54,6 +54,9 @@ defmodule Cachex.Spec do value: any ) + # Helper type for entry types + @type entries :: entry | [entry] + # Record specification for a cache expiration @type expiration :: record(:expiration,