couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject couch commit: updated refs/heads/2657-fix-cassim-fabric-calls to 369b75a
Date Mon, 20 Apr 2015 19:57:40 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/2657-fix-cassim-fabric-calls [created] 369b75a70


WIP: add couch_util:with_proc/{3,4}


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

Branch: refs/heads/2657-fix-cassim-fabric-calls
Commit: 369b75a707d83ccb2fff2ce24f699b2339b76a88
Parents: 43f1cfe
Author: Russell Branca <chewbranca@apache.org>
Authored: Mon Apr 20 19:57:20 2015 +0000
Committer: Russell Branca <chewbranca@apache.org>
Committed: Mon Apr 20 19:57:20 2015 +0000

----------------------------------------------------------------------
 src/couch_util.erl | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/369b75a7/src/couch_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_util.erl b/src/couch_util.erl
index 7e16866..87325ec 100644
--- a/src/couch_util.erl
+++ b/src/couch_util.erl
@@ -33,6 +33,7 @@
 -export([integer_to_boolean/1, boolean_to_integer/1]).
 -export([find_in_binary/2]).
 -export([callback_exists/3, validate_callback_exists/3]).
+-export([with_proc/3, with_proc/4]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -569,3 +570,22 @@ ensure_loaded(Module) when is_atom(Module) ->
         false
     end;
 ensure_loaded(_Module) -> false.
+
+
+with_proc(M, F, A) ->
+    with_proc(M, F, A, 60000).
+
+
+with_proc(M, F, A, Timeout) ->
+    {Pid, Ref} = spawn_monitor(fun() ->
+        exit(erlang:apply(M, F, A))
+    end),
+    receive
+        {'DOWN', Ref, process, Pid, Resp} ->
+            {ok, Resp};
+        {'DOWN', Ref, process, Pid, Error} ->
+            {error, Error}
+    after Timeout ->
+        erlang:demonitor(Ref, [flush]),
+        {error, timeout}
+    end.


Mime
View raw message