Skip to content

Commit e3465fb

Browse files
committed
Initializing pool correctly
1 parent 1d685a3 commit e3465fb

File tree

1 file changed

+13
-8
lines changed
  • packages/bolt-connection/src/pool

1 file changed

+13
-8
lines changed

packages/bolt-connection/src/pool/pool.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class Pool {
110110

111111
request = new PendingRequest(key, resolve, reject, timeoutId, this._log)
112112
allRequests[key].push(request)
113-
114-
this._processPendingAcquireRequests(address)
113+
const pool = this._getOrInitializePoolFor(key)
114+
this._processPendingAcquireRequests(address, pool)
115115
})
116116
}
117117

@@ -176,18 +176,23 @@ class Pool {
176176
return this._activeResourceCounts[address.asKey()] || 0
177177
}
178178

179-
async _acquire (address) {
180-
if (this._closed) {
181-
throw newError('Pool is closed, it is no more able to serve requests.')
182-
}
183-
184-
const key = address.asKey()
179+
_getOrInitializePoolFor (key) {
185180
let pool = this._pools[key]
186181
if (!pool) {
187182
pool = new SingleAddressPool()
188183
this._pools[key] = pool
189184
this._pendingCreates[key] = 0
190185
}
186+
return pool
187+
}
188+
189+
async _acquire (address) {
190+
if (this._closed) {
191+
throw newError('Pool is closed, it is no more able to serve requests.')
192+
}
193+
194+
const key = address.asKey()
195+
const pool = this._getOrInitializePoolFor(key)
191196
while (pool.length) {
192197
const resource = pool.pop()
193198

0 commit comments

Comments
 (0)