Packages
xandra
0.19.0
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.18.0-rc.9
0.18.0-rc.8
0.18.0-rc.7
0.18.0-rc.6
0.18.0-rc.5
0.18.0-rc.4
0.18.0-rc.3
0.18.0-rc.2
0.18.0-rc.1
0.17.0
0.16.0
0.15.0
0.15.0-rc.1
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.2
0.9.1
0.9.0
0.8.0
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
Fast, simple, and robust Cassandra driver for Elixir.
Current section
Files
Jump to
Current section
Files
lib/xandra/gen_statem_helpers.ex
defmodule Xandra.GenStatemHelpers do
@moduledoc false
# We use :gen_statem in some places, but name registration for it is tricky for example.
# This module provides a few helpers to mitigate that.
@spec split_opts(keyword()) :: {keyword(), keyword()}
def split_opts(opts) when is_list(opts) do
{gen_statem_opts, other_opts} = Keyword.split(opts, [:debug, :hibernate_after, :spawn_opt])
gen_statem_opts = Keyword.merge(gen_statem_opts, Keyword.take(other_opts, [:name]))
{gen_statem_opts, other_opts}
end
@spec start_link_with_name_registration(module(), term(), keyword()) :: :gen_statem.start_ret()
def start_link_with_name_registration(module, arg, gen_statem_opts_with_name)
when is_atom(module) and is_list(gen_statem_opts_with_name) do
case Keyword.fetch(gen_statem_opts_with_name, :name) do
:error ->
:gen_statem.start_link(module, arg, gen_statem_opts_with_name)
{:ok, atom} when is_atom(atom) ->
gen_statem_opts = Keyword.delete(gen_statem_opts_with_name, :name)
:gen_statem.start_link({:local, atom}, module, arg, gen_statem_opts)
{:ok, {:global, _term} = tuple} ->
gen_statem_opts = Keyword.delete(gen_statem_opts_with_name, :name)
:gen_statem.start_link(tuple, module, arg, gen_statem_opts)
{:ok, {:via, via_module, _term} = tuple} when is_atom(via_module) ->
gen_statem_opts = Keyword.delete(gen_statem_opts_with_name, :name)
:gen_statem.start_link(tuple, module, arg, gen_statem_opts)
{:ok, other} ->
raise ArgumentError, """
expected :name option to be one of the following:
* nil
* atom
* {:global, term}
* {:via, module, term}
Instead, got: #{inspect(other)}\
"""
end
end
end