From db1df67fadcbf4077c9d011d7f68c95611b5feaf Mon Sep 17 00:00:00 2001 From: pei Date: Wed, 28 Aug 2019 15:29:52 +0800 Subject: [PATCH] worker for event handler --- src/workitem_worker.erl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/workitem_worker.erl b/src/workitem_worker.erl index b78645c..08cb3bf 100644 --- a/src/workitem_worker.erl +++ b/src/workitem_worker.erl @@ -149,6 +149,8 @@ handle_call({on, Fun}, _From, State) -> NewState -> {reply, noreply, NewState} end; +handle_call(Request, From, State = #{handle := MFA}) -> + handle_X(MFA, call, {Request, From}, State); handle_call(_Request, _From, State) -> {reply, ok, State}. @@ -169,13 +171,25 @@ handle_cast({on, Fun}, State) -> NewState -> {noreply, NewState} end; +handle_cast(Info, State = #{handle := MFA}) -> + handle_X(MFA, cast, Info, State); handle_cast(_Request, State) -> {noreply, State}. +handle_info(Info, State = #{handle := MFA}) -> + handle_X(MFA, info, Info, State); +%% M:F(info, Info, State, A); +%% {noreply, State}; handle_info(_Info, State) -> {noreply, State}. +handle_X({M,F,A}, X, What, State)-> + M:F(X, What, State, A); +handle_X({M,F}, X, What, State)-> + M:F(X, What, State). + + terminate(_Reason, _State) -> ok.