Last active
May 5, 2016 12:40
-
-
Save devinivy/7bbbdab92d96d4c4b1bfd22fb7191668 to your computer and use it in GitHub Desktop.
Knex locked connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Knex = require('./knex'); | |
const knex = Knex({ | |
dialect: 'postgres', | |
connection: { | |
adapter: 'postgresql', | |
database: 'test', | |
user: 'postgres' | |
}, | |
pool: { | |
min: 2, | |
max: 2, | |
// requestTimeout: 1 // Uncomment to make example work | |
}, | |
acquireConnectionTimeout: 2 | |
}); | |
knex.raw('SELECT 1') | |
.catch((err) => console.error('Expected1', err)) | |
.then(() => knex.raw('SELECT 1')) | |
.catch((err) => console.error('Expected2', err)) | |
.then(() => { | |
return new Promise((res, req) => { | |
setTimeout(() => { | |
console.log('Waited– a connection should be available despite previous errors'); | |
// knex.client.pool.requestTimeout = 10000; // Uncomment to make example work | |
knex.client.config.acquireConnectionTimeout = 10000; | |
res(); | |
}, 100); | |
}); | |
}) | |
.then(() => knex.raw('SELECT 1')) | |
.then(() => knex.raw('SELECT 1')) | |
.catch((err) => console.error('Unexpected', err, err.stack)) | |
.then(() => process.exit(0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment