summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_work_queue.erl
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2010-08-21 20:23:06 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2010-08-21 20:23:06 +0000
commit043671429beae470fa9560bfaab0a45324c8f956 (patch)
tree89d26a801b549056bb34343a398d99d0799fdeef /src/couchdb/couch_work_queue.erl
parent9b3c2688feba69fe178b4d1e9ecff5c1a36c9475 (diff)
Small refactoring of the work queue module to accomodate for incoming options (multiple workers)
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@987824 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_work_queue.erl')
-rw-r--r--src/couchdb/couch_work_queue.erl14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/couchdb/couch_work_queue.erl b/src/couchdb/couch_work_queue.erl
index decfcad8..44f2816d 100644
--- a/src/couchdb/couch_work_queue.erl
+++ b/src/couchdb/couch_work_queue.erl
@@ -13,7 +13,7 @@
-module(couch_work_queue).
-behaviour(gen_server).
--export([new/2,queue/2,dequeue/1,dequeue/2,close/1]).
+-export([new/1,queue/2,dequeue/1,dequeue/2,close/1]).
-export([init/1, terminate/2, handle_call/3, handle_cast/2, code_change/3, handle_info/2]).
-record(q, {
@@ -27,8 +27,8 @@
close_on_dequeue=false
}).
-new(MaxSize, MaxItems) ->
- gen_server:start_link(couch_work_queue, {MaxSize, MaxItems}, []).
+new(Options) ->
+ gen_server:start_link(couch_work_queue, Options, []).
queue(Wq, Item) ->
gen_server:call(Wq, {queue, Item}, infinity).
@@ -46,8 +46,12 @@ close(Wq) ->
gen_server:cast(Wq, close).
-init({MaxSize,MaxItems}) ->
- {ok, #q{max_size=MaxSize, max_items=MaxItems}}.
+init(Options) ->
+ Q = #q{
+ max_size = couch_util:get_value(max_size, Options),
+ max_items = couch_util:get_value(max_items, Options)
+ },
+ {ok, Q}.
terminate(_Reason, #q{work_waiter=nil}) ->
ok;