mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Based on the suggestion from #2078. This adds ref/unref methods to the Connection and Client classes and then uses them to allow the process to exit if all of the connections in the pool are idle. This behavior is controlled by the allowExitOnIdle flag to the Pool constructor; it defaults to the old behavior.
17 lines
579 B
JavaScript
17 lines
579 B
JavaScript
// This test is meant to be spawned from idle-timeout.js
|
|
if (module === require.main) {
|
|
const allowExitOnIdle = process.env.ALLOW_EXIT_ON_IDLE === '1'
|
|
const Pool = require('../index')
|
|
|
|
const pool = new Pool({ idleTimeoutMillis: 200, ...(allowExitOnIdle ? { allowExitOnIdle: true } : {}) })
|
|
pool.query('SELECT NOW()', (err, res) => console.log('completed first'))
|
|
pool.on('remove', () => {
|
|
console.log('removed')
|
|
done()
|
|
})
|
|
|
|
setTimeout(() => {
|
|
pool.query('SELECT * from generate_series(0, 1000)', (err, res) => console.log('completed second'))
|
|
}, 50)
|
|
}
|