anchor.diff:      },
       {ok, Q}.
   
  +
   terminate(_Reason, #q{work_waiters=Workers}) ->
       lists:foreach(fun({W, _}) -> gen_server:reply(W, closed) end, Workers).
  +
       
  -handle_call({queue, Item}, From, #q{work_waiters=[]}=Q0) ->
  -    Q = Q0#q{size=Q0#q.size + byte_size(term_to_binary(Item)),
  -                items=Q0#q.items + 1,
  -                queue=queue:in(Item, Q0#q.queue)},
  +handle_call({queue, Item}, From, #q{work_waiters = []} = Q0) ->
  +    Q = Q0#q{size = Q0#q.size + byte_size(term_to_binary(Item)),
  +                items = Q0#q.items + 1,
  +                queue = queue:in(Item, Q0#q.queue)},
       case (Q#q.size >= Q#q.max_size) orelse
               (Q#q.items >= Q#q.max_items) of
       true ->
  -        {noreply, Q#q{blocked=[From | Q#q.blocked]}};
  +        {noreply, Q#q{blocked = [From | Q#q.blocked]}};
       false ->
           {reply, ok, Q}
       end;
  +
   handle_call({queue, Item}, _From, #q{work_waiters = [{W, _Max} | Rest]} = Q) ->
       gen_server:reply(W, {ok, [Item]}),
  -    {reply, ok, Q#q{work_waiters=Rest}};
  +    {reply, ok, Q#q{work_waiters = Rest}};
   
   handle_call({dequeue, Max}, From, Q) ->
       #q{work_waiters = Workers, multi_workers = Multi, items = Count} = Q,
  
positive.code: -module(couch_work_queue).
  -behaviour(gen_server).
  
  -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, {
      queue=queue:new(),
      blocked=[],
      max_size,
      max_items,
      items=0,
      size=0,
      work_waiters=[],
      close_on_dequeue=false,
      multi_workers=false
  }).
  
  new(Options) ->
      gen_server:start_link(couch_work_queue, Options, []).
  
  queue(Wq, Item) ->
      gen_server:call(Wq, {queue, Item}, infinity).
  
  dequeue(Wq) ->
      dequeue(Wq, all).
      
  dequeue(Wq, MaxItems) ->
      try gen_server:call(Wq, {dequeue, MaxItems}, infinity)
      catch
          _:_ -> closed
      end.
  
  close(Wq) ->
      gen_server:cast(Wq, close).
  
negative.code:             deliver_queue_items(Max, Q)
          end
      end.
  
  
  deliver_queue_items(Max, Q) ->
      #q{
  