1 使用gen_event模块之前, 第一步就是用gen_event:start_link方法生成一个event manager进程。切记,只有这个进程才可以绑定handler。
2 真正的event处理器是需要behaviour(gen_event)的模块, behaviour的时候需要生成的回调函数:
init/1
handle_event/2
handle_call/3
code_change
terminate
3 handle_event 是异步处理event的函数
4 handle_call 是同步处理函数, 一定会返回某个值
5 一个event manager进程可以绑定多个event handler, 同一个消息会同时发送给多个handler进行处理。
6 process_info(Pid)可以查看一个进程的状态:
1> process_info(self()).
[{current_function,{erl_eval,do_apply,6}},
{initial_call,{erlang,apply,2}},
{status,running},
{message_queue_len,0},
{messages,[]},
{links,[<0.27.0>]},
{dictionary,[]},
{trap_exit,false},
{error_handler,error_handler},
{priority,normal},
{group_leader,<0.26.0>},
{total_heap_size,609},
{heap_size,233},
{stack_size,24},
{reductions,522},
{garbage_collection,[{min_bin_vheap_size,46422},
{min_heap_size,233},
{fullsweep_after,65535},
{minor_gcs,7}]},
{suspending,[]}]
7 pid(0,33,0). 函数可以生成一个真正的PID
------------------------------
周末愉快,推荐听一首歌杨乃文的《祝我幸福》