As per OTP guide
The idea is to divide the code for a process in a generic part (a behaviour module) and a specific part (a callback module ).
So, will this piece of code, mainly the callbacks (init, handle_cast and handle_call)
defmodule Stack do
use GenServer
def start_link(state) do
GenServer.start_link(__MODULE__, state, name: __MODULE__)
end
## Callbacks
@impl true
def init(stack) do
{:ok, stack}
end
@impl true
def handle_call(:pop, _from, [head | tail]) do
{:reply, head, tail}
end
@impl true
def handle_cast({:push, head}, tail) do
{:noreply, [head | tail]}
end
end
override the default implementation of those function in Supervisior module?
For eg, Will this init function be overriden ?
def init(children, options) when is_list(children) and is_list(options) do
unless strategy = options[:strategy] do
raise ArgumentError, "expected :strategy option to be given"
end
intensity = Keyword.get(options, :max_restarts, 3)
period = Keyword.get(options, :max_seconds, 5)
flags = %{strategy: strategy, intensity: intensity, period: period}
{:ok, {flags, Enum.map(children, &init_child/1)}}
end