Open
Description
Are there any issues with this pattern of code:
let pool = new Pool({ max: 5 });
pool.on('connect', (client) => {
client._ready = new Promise((resolve, reject) => {
client.query('SET search_path to foo, public', (err) => {
if(err) {
reject(err);
} else {
resolve();
}
});
});
});
//...some other place
pool.getConnection(function(err, client, release) {
if(err) {
// error handling
}
client._ready.then(() => {
//run some query and on success release the client back to pool
//if errors post query execution then also release client back to pool
}).catch(err2 => {
//some other kind of error handling
});
});
Inside getConnection()
callback function, will _ready
always be a promise? Can it ever become undefined
? 🤔