* Closes the connection and removes a connection from the pool. * @param {Connection} connection
(connection)
| 307 | * @param {Connection} connection |
| 308 | */ |
| 309 | remove(connection) { |
| 310 | // locating an object by position in the array is O(n), but normally there should be between 1 to 8 connections. |
| 311 | const index = this.connections.indexOf(connection); |
| 312 | if (index < 0) { |
| 313 | // it was already removed from the connections and it's closing |
| 314 | return; |
| 315 | } |
| 316 | // remove the connection from the pool, using an pool copy |
| 317 | const newConnections = this.connections.slice(0); |
| 318 | newConnections.splice(index, 1); |
| 319 | this.connections = newConnections; |
| 320 | // close the connection |
| 321 | setImmediate(function removeClose() { |
| 322 | connection.close(); |
| 323 | }); |
| 324 | this.emit('remove'); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * @param {Number} delay |