From 043671429beae470fa9560bfaab0a45324c8f956 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Sat, 21 Aug 2010 20:23:06 +0000 Subject: 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 --- src/couchdb/couch_work_queue.erl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/couchdb/couch_work_queue.erl') 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; -- cgit v1.2.3