fix: stop resource when resource manager terminates

This commit is contained in:
Zaiming (Stone) Shi 2023-01-27 12:15:07 +01:00
parent 30a8a436b4
commit d53106145f
1 changed files with 2 additions and 2 deletions

View File

@ -309,6 +309,7 @@ init({Data, Opts}) ->
end. end.
terminate(_Reason, _State, Data) -> terminate(_Reason, _State, Data) ->
_ = stop_resource(Data),
_ = maybe_clear_alarm(Data#data.id), _ = maybe_clear_alarm(Data#data.id),
delete_cache(Data#data.id, Data#data.manager_id), delete_cache(Data#data.id, Data#data.manager_id),
ok. ok.
@ -334,8 +335,7 @@ handle_event({call, From}, start, _State, _Data) ->
% Called when the resource received a `quit` message % Called when the resource received a `quit` message
handle_event(info, quit, stopped, _Data) -> handle_event(info, quit, stopped, _Data) ->
{stop, {shutdown, quit}}; {stop, {shutdown, quit}};
handle_event(info, quit, _State, Data) -> handle_event(info, quit, _State, _Data) ->
_ = stop_resource(Data),
{stop, {shutdown, quit}}; {stop, {shutdown, quit}};
% Called when the resource is to be stopped % Called when the resource is to be stopped
handle_event({call, From}, stop, stopped, _Data) -> handle_event({call, From}, stop, stopped, _Data) ->