Skip to content

Commit

Permalink
Merge branch 'at/terminate-can-modify-state' into pu
Browse files Browse the repository at this point in the history
* at/terminate-can-modify-state:
  Add ability for gen_(server|fsm):terminate to modify state sent to error_logger
  • Loading branch information
bjorng committed Feb 25, 2010
2 parents 9d78f7b + aedff05 commit 4774882
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
8 changes: 7 additions & 1 deletion lib/stdlib/doc/src/gen_fsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,13 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
<p>This function is called by a gen_fsm when it is about to
terminate. It should be the opposite of <c>Module:init/1</c>
and do any necessary cleaning up. When it returns, the gen_fsm
terminates with <c>Reason</c>. The return value is ignored.</p>
terminates with <c>Reason</c>. The return
value is ignored except in the special case of the function
returning <c>{error_info, StateData}</c> which indicates that
the module wants that modified state data to be passed to
<c>error_logger:format/2</c> instead of the original state data.</p>
<p><c>Reason</c> is a term denoting the stop reason and
<c>State</c> is the internal state of the gen_server.</p>
<p><c>Reason</c> is a term denoting the stop reason,
<c>StateName</c> is the current state name, and
<c>StateData</c> is the state data of the gen_fsm.</p>
Expand Down
5 changes: 4 additions & 1 deletion lib/stdlib/doc/src/gen_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,10 @@ gen_server:abcast -----> Module:handle_cast/2
terminate. It should be the opposite of <c>Module:init/1</c>
and do any necessary cleaning up. When it returns,
the gen_server terminates with <c>Reason</c>. The return
value is ignored.</p>
value is ignored except in the special case of the function
returning <c>{error_info, State}</c> which indicates that
the module wants that modified state data to be passed to
<c>error_logger:format/2</c> instead of the original state data.</p>
<p><c>Reason</c> is a term denoting the stop reason and
<c>State</c> is the internal state of the gen_server.</p>
<p><c>Reason</c> depends on why the gen_server is terminating.
Expand Down
11 changes: 9 additions & 2 deletions lib/stdlib/src/gen_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ terminate(Reason, Name, Msg, Mod, StateName, StateData, Debug) ->
{'EXIT', R} ->
error_info(R, Name, Msg, StateName, StateData, Debug),
exit(R);
_ ->
Res ->
case Reason of
normal ->
exit(normal);
Expand All @@ -542,7 +542,14 @@ terminate(Reason, Name, Msg, Mod, StateName, StateData, Debug) ->
{shutdown,_}=Shutdown ->
exit(Shutdown);
_ ->
error_info(Reason, Name, Msg, StateName, StateData, Debug),
ErrorStateData =
case Res of
{error_info, NewStateData} ->
NewStateData;
_ ->
StateData
end,
error_info(Reason, Name, Msg, StateName, ErrorStateData, Debug),
exit(Reason)
end
end.
Expand Down
11 changes: 9 additions & 2 deletions lib/stdlib/src/gen_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ terminate(Reason, Name, Msg, Mod, State, Debug) ->
{'EXIT', R} ->
error_info(R, Name, Msg, State, Debug),
exit(R);
_ ->
Res ->
case Reason of
normal ->
exit(normal);
Expand All @@ -705,7 +705,14 @@ terminate(Reason, Name, Msg, Mod, State, Debug) ->
{shutdown,_}=Shutdown ->
exit(Shutdown);
_ ->
error_info(Reason, Name, Msg, State, Debug),
ErrorState =
case Res of
{error_info, NewState} ->
NewState;
_ ->
State
end,
error_info(Reason, Name, Msg, ErrorState, Debug),
exit(Reason)
end
end.
Expand Down

0 comments on commit 4774882

Please sign in to comment.