``` release(item) { const index = this.items.indexOf(item); if (index < 0) throw new Error('Pool: release unexpected item'); if (this.free[index]) throw new Error('Pool: release not captured'); this.free[index] = true; this.available++; if (this.queue.length > 0) { const { resolve, timer } = this.queue.shift(); clearTimeout(timer); if (resolve) setTimeout(resolve, 0, item); } } ``` error - we should not free released item if we resolve it for user in queue ``` release(item) { const index = this.items.indexOf(item); if (index < 0) throw new Error('Pool: release unexpected item'); if (this.free[index]) throw new Error('Pool: release not captured'); if (this.queue.length > 0) { const { resolve, timer } = this.queue.shift(); clearTimeout(timer); if (resolve) setTimeout(resolve, 0, item); } else { this.free[index] = true; this.available++; } } ```
Activity