anchor.diff:  
   %% -- internal functions --
   
  -connect(N, Opts) ->
  -    connect(N, Opts, []).
  -
  -connect(0, _Opts, Acc) ->
  -    Acc;
  -connect(N, Opts, Acc) ->
  +connect(Opts) ->
       Host     = proplists:get_value(host, Opts),
       Username = proplists:get_value(username, Opts),
       Password = proplists:get_value(password, Opts),
  -    {ok, C} = pgsql:connect(Host, Username, Password, Opts),
  -    connect(N - 1, Opts, [{C, z_utils:now()} | Acc]).
  +    pgsql:connect(Host, Username, Password, Opts).
   
  -deliver(Pid, C, State) ->
  -    #state{id = Id, connections = Connections, monitors = Monitors} = State,
  -    Pid ! {pgsql_pool, Id, {connection, C}},
  -    receive
  -        {pgsql_pool, Id, {ack, Pid, C}} ->
  -            M = erlang:monitor(process, Pid),
  -            Monitors2 = [{C, M} | Monitors],
  -            State#state{monitors = Monitors2}
  -    after
  -        100 ->
  -            State#state{connections = [{C, z_utils:now()} | Connections]}
  +deliver({Pid,_Tag} = From, C, #state{monitors=Monitors} = State) ->
  +    M = erlang:monitor(process, Pid),
  +	gen_server:reply(From, {ok, C}),
  +	State#state{ monitors=[{C, M} | Monitors] }.
  +
  +return(C, #state{connections = Connections, waiting = Waiting} = State) ->
  +    case queue:out(Waiting) of
  +        {{value, From}, Waiting2} ->
  +            State2 = deliver(From, C, State),
  +            State2#state{waiting = Waiting2};
  +        {empty, _Waiting} ->
  +            Connections2 = [{C, now_secs()} | Connections],
  +            State#state{connections = Connections2}
       end.
   
  -return(C, State) ->
  -    #state{connections = Connections, waiting = Waiting} = State,
  -    case queue:out(Waiting) of
  -        {{value, Pid}, Waiting2} ->
  -            State2 = deliver(Pid, C, State),
  -            State2#state{waiting = Waiting2};
  -        {empty, _Waiting} ->
  -            Connections2 = [{C, z_utils:now()} | Connections],
  -            State#state{connections = Connections2}
  -    end.
  +
  +%% Return the current time in seconds, used for timeouts.
  +now_secs() ->
  +    {M,S,_M} = erlang:now(),
  +    M*1000 + S.
  
positive.code: -record(state, {id, size, connections, monitors, waiting, opts, timer}).
  
   %% -- client interface --
  -include_lib("zotonic.hrl").
  
  opts(Opts) ->
      Defaults = [{host, "localhost"},
  
negative.code: start_link(Name, Size, Opts) ->
      gen_server:start_link({local, Name}, ?MODULE, {Name, Size, opts(Opts)}, []).
  
  %% @doc Stop the pool, close all db connections
  stop(P) ->
      gen_server:cast(P, stop).
  
  %% @doc Get a db connection, wait at most 10 seconds before giving up.
  get_connection(P) ->
      get_connection(P, 10000).
  
  %% @doc Get a db connection, wait at most Timeout seconds before giving up.
  get_connection(P, Timeout) ->
  	try
      	gen_server:call(P, get_connection, Timeout)
  	catch 
  		_:_ ->
              gen_server:cast(P, {cancel_wait, self()}),
              {error, timeout}
  	end.
  
  %% @doc Return a db connection back to the connection pool.
  return_connection(P, C) ->
      gen_server:cast(P, {return_connection, C}).
  
  %% @doc Return the name of the database used for the pool.
  get_database(P) ->
      {ok, C} = get_connection(P),
      {ok, Db} = pgsql_connection:database(C),
  