Skip to content

Commit dc0d600

Browse files
Dan Bernardicdougwilson
Dan Bernardic
authored andcommitted
docs: add pool.end() documentation
closes #911 closes #912
1 parent a4dd3dc commit dc0d600

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Readme.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,27 @@ pool.on('enqueue', function () {
364364
});
365365
```
366366

367+
## Closing all the connections in a pool
368+
369+
When you are done using the pool, you have to end all the connections or the
370+
Node.js event loop will stay active until the connections are closed by the
371+
MySQL server. This is typically done if the pool is used in a script or when
372+
trying to gracefully shutdown a server. To end all the connections in the
373+
pool, use the `end` method on the pool:
374+
375+
```js
376+
pool.end(function (err) {
377+
// all connections in the pool have ended
378+
});
379+
```
380+
381+
The `end` method takes an _optional_ callback that you can use to know once
382+
all the connections have ended. The connections end _gracefully_, so all
383+
pending queries will still complete and the time to end the pool will vary.
384+
385+
**Once `pool.end()` has been called, `pool.getConnection` and other operations
386+
can no longer be performed**
387+
367388
## PoolCluster
368389

369390
PoolCluster provides multiple hosts connection. (group & retry & selector)

0 commit comments

Comments
 (0)