Požičiava drahé objekty zo zásoby a po použití ich berie späť.
class Connection { execute(query) { // work over an expensive resource }} class ConnectionPool { #free = []; #borrowed = new Set(); constructor(count) { for (let i = 0; i < count; i += 1) { this.#free.push(new Connection()); } } acquire() { if (this.#free.length === 0) { throw new Error('pool is empty'); } const connection = this.#free.pop(); this.#borrowed.add(connection); return connection; } release(connection) { this.#borrowed.delete(connection); this.#free.push(connection); }} const pool = new ConnectionPool(3); const a = pool.acquire();const b = pool.acquire(); pool.release(a);const c = pool.acquire(); a === c; // true — the pool handed out the same object again