diff options
author | Zandra Norman <[email protected]> | 2017-01-23 16:07:52 +0100 |
---|---|---|
committer | Zandra Norman <[email protected]> | 2017-04-21 15:02:49 +0200 |
commit | db632b91f41c4a01be68d821d6942ff32b86e40b (patch) | |
tree | bc9d2e109735a34b3f9b18942f0a18df7aed2210 /lib/stdlib/src/gen_event.erl | |
parent | 8ca53b0f993ffbf2991e3068b76ec15b8f5eca51 (diff) | |
download | otp-db632b91f41c4a01be68d821d6942ff32b86e40b.tar.gz otp-db632b91f41c4a01be68d821d6942ff32b86e40b.tar.bz2 otp-db632b91f41c4a01be68d821d6942ff32b86e40b.zip |
stdlib: Make gen_event callbacks optional
Diffstat (limited to 'lib/stdlib/src/gen_event.erl')
-rw-r--r-- | lib/stdlib/src/gen_event.erl | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/stdlib/src/gen_event.erl b/lib/stdlib/src/gen_event.erl index 0aebf1bdc5..0c50b2aa08 100644 --- a/lib/stdlib/src/gen_event.erl +++ b/lib/stdlib/src/gen_event.erl @@ -109,7 +109,8 @@ State :: term(), Status :: term(). --optional_callbacks([format_status/2]). +-optional_callbacks( + [handle_info/2, terminate/2, code_change/3, format_status/2]). %%--------------------------------------------------------------------------- @@ -577,6 +578,10 @@ server_update(Handler1, Func, Event, SName) -> do_terminate(Mod1, Handler1, remove_handler, State, remove, SName, normal), no; + {'EXIT', {undef, [{Mod1, handle_info, [_,_], _}|_]}} -> + error_logger:warning_msg("** Undefined handle_info in ~p~n" + "** Unhandled message: ~p~n", [Mod1, Event]), + {ok, Handler1}; Other -> do_terminate(Mod1, Handler1, {error, Other}, State, Event, SName, crash), @@ -698,9 +703,15 @@ server_call_update(Handler1, Query, SName) -> end. do_terminate(Mod, Handler, Args, State, LastIn, SName, Reason) -> - Res = (catch Mod:terminate(Args, State)), - report_terminate(Handler, Reason, Args, State, LastIn, SName, Res), - Res. + case erlang:function_exported(Mod, terminate, 2) of + true -> + Res = (catch Mod:terminate(Args, State)), + report_terminate(Handler, Reason, Args, State, LastIn, SName, Res), + Res; + false -> + report_terminate(Handler, Reason, Args, State, LastIn, SName, ok), + ok + end. report_terminate(Handler, crash, {error, Why}, State, LastIn, SName, _) -> report_terminate(Handler, Why, State, LastIn, SName); |