int id = 0; class Connection { public int id; } auto pool = new ConnectionPool!Connection({ auto conn = new Connection(); // perform the connection here conn.id = id++; return conn; }); // create and lock a first connection auto c1 = pool.lockConnection(); assert(c1.id == 0); pool.remove(c1); destroy(c1); auto c2 = pool.lockConnection(); assert(c2.id == 1); // assert that we got a new connection pool.remove(c2); pool.add(c2); destroy(c2); auto c3 = pool.lockConnection(); assert(c3.id == 1); // should get the same connection back