anchor.diff:  -module(http_queue).
   -export([new/2, add/2, remove/2]).
   
  --record(q, {max_waiting, max_active, waiters, active}).
  +-record(q, {max_waiting :: non_neg_integer(),
  +            max_active :: non_neg_integer(),
  +            waiters :: [{T, fun(() -> _)}],
  +            active :: [T]}).
   
  +-type q() :: #q{}.
  +
  +-spec new(non_neg_integer(), non_neg_integer()) -> #q{}.
   new(MaxActive, MaxWaiting) ->
       #q{max_waiting = MaxWaiting,
          max_active = MaxActive,
          waiters = [],
          active = []}.
  +
  +-spec add({_, fun(() -> _)}, q()) -> {{'active', _} | 'wait', q()} | 'full'.
   
   add({Id, Fun}, #q{max_active = MaxA, active = A} = Q) when length(A) < MaxA ->
       {{active, Fun()}, Q#q{active = [Id|A]}};
  
positive.code: 
  add(_E, _Q) -> full.
  
  remove(Id, #q{active = A, waiters = W} = Q) ->
      case A -- [Id] of
          L when L =:= A ->
  
negative.code:             wake(Q#q{active = L})
      end.
  
  -spec wake(#q{}) -> {'wait' | {'active', _}, #q{}}.
  wake(#q{waiters = []} = Q) ->
      {wait, Q};
  wake(#q{waiters = W} = Q) ->
      [E|R] = lists:reverse(W),
      add(E, Q#q{waiters = lists:reverse(R)}).
  