Skip to content

Commit

Permalink
Correctly handle init/1 {:ok, state, options}
Browse files Browse the repository at this point in the history
  • Loading branch information
IceDragon200 committed Jun 20, 2024
1 parent cfe67dc commit a5af689
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/freddy/core/actor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,28 @@ defmodule Freddy.Core.Actor do
@impl true
def init({mod, config, initial}) do
case mod.init(initial) do
{:ok, given} -> {:ok, state(mod: mod, config: config, given: given)}
ignore_or_stop -> ignore_or_stop
{:ok, given} ->
{:ok, state(mod: mod, config: config, given: given)}

{:ok, given, options} ->
{:ok, state(mod: mod, config: config, given: given), options}

:ignore ->
:ignore

{:stop, _reason} = stop ->
stop
end
end

@impl true
def handle_disconnected(reason, state(mod: mod, given: given) = state) do
case mod.handle_disconnected(reason, given) do
{:noreply, new_given} -> {:noreply, state(state, given: new_given)}
{:stop, reason, new_given} -> {:stop, reason, state(state, given: new_given)}
{:noreply, new_given} ->
{:noreply, state(state, given: new_given)}

{:stop, reason, new_given} ->
{:stop, reason, state(state, given: new_given)}
end
end

Expand Down

0 comments on commit a5af689

Please # to comment.