• 事件通知

    事件通知

    1. 3> gen_event:notify(error_man, no_reply).
    2. ***Error*** no_reply
    3. ok

    error_man 是事件管理器的名字, no_reply 是事件。

    事件被作为一个消息发送给事件管理器。当收到了这个事件以后,事件管理器为每个安装了的事件处理器按照他们添加的顺序调用 handle_event(Event,State) 。函数要返回一个元组 {ok,State1} ,其中 State1 是事件处理器的状态的新值。

    terminal_logger 中:

    1. handle_event(ErrorMsg, State) ->
    2. io:format("***Error*** ~p~n", [ErrorMsg]),
    3. {ok, State}.
    1. handle_event(ErrorMsg, Fd) ->
    2. io:format(Fd, "***Error*** ~p~n", [ErrorMsg]),
    3. {ok, Fd}.