Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Implement option to provide a parent to monitor
The couch_event_listener_mfa already had the necessary logic for
monitoring the parent process that spawned it for a start_link usage. In
some instances we have rexi_worker process use the enter_loop style APIs
to avoid the need to spawn a separate process. This just adds an option
`{parent, pid()}` that allows these processes to specify the parent to
monitor.
  • Loading branch information
davisp authored and rnewson committed Jul 30, 2014
1 parent 707997e commit fbe7ae64dcd72a09f4cd7bd2999dfff7a4412171
Showing 1 changed file with 12 additions and 2 deletions.
@@ -38,15 +38,25 @@


start_link(Mod, Func, State, Options) ->
Arg = {self(), Mod, Func, State},
Parent = case proplists:get_value(parent, Options) of
P when is_pid(P) -> P;
_ -> self()
end,
Arg = {Parent, Mod, Func, State},
couch_event_listener:start_link(?MODULE, Arg, Options).


enter_loop(Mod, Func, State, Options) ->
Parent = case proplists:get_value(parent, Options) of
P when is_pid(P) -> P;
_ -> undefined
end,
erlang:monitor(process, Parent),
St = #st{
mod = Mod,
func = Func,
state = State
state = State,
parent = Parent
},
couch_event_listener:enter_loop(?MODULE, St, Options).

0 comments on commit fbe7ae6

Please sign in to comment.