Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
New couch_event:listen/4 API
Browse files Browse the repository at this point in the history
This function doesn't return but allows a process to become an event
listener. Useful in RPC situations to avoid spawning an extra process
and doubling the message passing.
  • Loading branch information
davisp authored and rnewson committed Jul 30, 2014
1 parent bf25e9f commit b00c879
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/couch_event.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ notify(DbName, Event) ->
gen_server:cast(?DIST, {DbName, Event}).


listen(Module, Function, State, Options) ->
couch_event_listener_mfa:enter_loop(Module, Function, State, Options).


link_listener(Module, Function, State, Options) ->
couch_event_listener_mfa:start_link(Module, Function, State, Options).

Expand Down
12 changes: 11 additions & 1 deletion src/couch_event_listener_mfa.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

-export([
start_link/4,
stop/1
enter_loop/4,
stop/1,
]).

-export([
Expand All @@ -41,6 +42,15 @@ start_link(Mod, Func, State, Options) ->
couch_event_listener:start_link(?MODULE, Arg, Options).


enter_loop(Mod, Func, State, Options) ->
St = #st{
mod = Mod,
func = Func,
state = State
},
couch_event_listener:enter_loop(?MODULE, St, Options).


stop(Pid) ->
couch_event_listener:stop(Pid).

Expand Down

0 comments on commit b00c879

Please sign in to comment.