You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/01 11:10:29 UTC

[33/35] git commit: Implement option to provide a parent to monitor

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.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/commit/fbe7ae64
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/tree/fbe7ae64
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/diff/fbe7ae64

Branch: refs/heads/windsor-merge
Commit: fbe7ae64dcd72a09f4cd7bd2999dfff7a4412171
Parents: 707997e
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Aug 8 12:15:32 2013 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Jul 30 17:49:52 2014 +0100

----------------------------------------------------------------------
 src/couch_event_listener_mfa.erl | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-event/blob/fbe7ae64/src/couch_event_listener_mfa.erl
----------------------------------------------------------------------
diff --git a/src/couch_event_listener_mfa.erl b/src/couch_event_listener_mfa.erl
index 4ffa92b..acc646c 100644
--- a/src/couch_event_listener_mfa.erl
+++ b/src/couch_event_listener_mfa.erl
@@ -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).