Skip to content

Commit

Permalink
Correctly implement the code_change callback
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Aug 12, 2024
1 parent c2295c5 commit 2de0ac5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/wpool_process.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ terminate(Reason, State) ->
end.

%% @private
-spec code_change(string(), state(), any()) -> {ok, state()} | {error, term()}.
-spec code_change(string() | {down, string()}, state(), any()) ->
{ok, state()} | {error, term()}.
code_change(OldVsn, #state{mod = #callback_cache{module = Mod}} = State, Extra) ->
case erlang:function_exported(Mod, code_change, 3) of
true ->
case Mod:code_change(OldVsn, State#state.state, Extra) of
{ok, NewState} ->
{ok, State#state{state = NewState}};
Error ->
{error, Error} ->
{error, Error}
end;
_ ->
Expand Down
2 changes: 1 addition & 1 deletion test/wpool_process_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ complete_coverage(_Config) ->
ct:comment("Code Change"),
{ok, State} = wpool_process:init({complete_coverage, echo_server, {ok, state}, []}),
{ok, _} = wpool_process:code_change("oldvsn", State, {ok, state}),
{error, bad} = wpool_process:code_change("oldvsn", State, bad),
{error, bad} = wpool_process:code_change("oldvsn", State, {error, bad}),

{comment, []}.

Expand Down

0 comments on commit 2de0ac5

Please sign in to comment.