new Pool(options)
- Description:
Create a resource pool,
createandclosecallbacks must be given which perform allocation and deallocation of the resources like db connections.
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | defines the following properties Properties
|
Example
var pool = new lib.Pool({
min: 1,
max: 5,
create: function(cb) {
someDb.connect((err) => { cb(err, this) }
},
destroy: function(client) {
client.close() }
})
});
pool.use((err, client) => {
...
pool.release(client);
});
const { err, client } = await pool.ause();
if (!err) {
...
pool.release(client);
}