开发者

Notify and stop gen_event manager atomically

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开发者_Go百科. I would prefer to have an approach that imposes no requirements on handlers.


As far as I know, there is no other way to do it than the one you're using for handling in a way that is truly limited to one call, outside of just plainly killing the event manager with exit(Pid, Reason) or ordering it to be shut down by its own supervisor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜