When a particular message is received by my gen_event manager process, I want it to stop after all handlers have handled it and before they get and handle any other events. The only way I could find is this:
-module(manager).
...
stop(Reason) ->
gen_event:sync_notify(manager, {stop, Reason}),
gen_event:stop(manager).
But this requires all handlers to return remove_handler from handle_event({stop, Reason}, State), otherwise they could handle an event sent from a different process after sync_notify and before stop. I would prefer to have an approach that imposes no requirements on handlers.