Skip to content

Commit

Permalink
Improvements to the GenServer and Supervisor snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
craigp authored and lpil committed Oct 13, 2022
1 parent 9a7f396 commit 5385107
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions snippets/elixir.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,27 @@ snippet genserver basic genserver structure
use GenServer

@doc false
def start_link do
GenServer.start_link(__MODULE__, ${1:Map.new})
def start_link(init_args) do
GenServer.start_link(__MODULE__, init_args, name: __MODULE__)
end

@impl true
def init(state) do
{:ok, state}
def init(_init_args) do
{:ok, []}
end
snippet genserver: basic genserver structure
use GenServer
snippet super basic supervisor structure
use Supervisor

@doc false
def start_link, do: GenServer.start_link(__MODULE__, ${1:Map.new})
def start_link(init_args) do
Supervisor.start_link(__MODULE__, init_args, name: __MODULE__)
end

@impl true
def init(state), do: {:ok, state}
def init(_init_args) do
children = [${1}]
Supervisor.init(children, strategy: :one_for_one)
end
snippet impl
@impl true
def ${1:name} do
Expand Down

0 comments on commit 5385107

Please sign in to comment.