-
Notifications
You must be signed in to change notification settings - Fork 260
Open
Description
I make 20 request after create connection pool with 10 max connection, but always got “Resource not currently part of this pool”。Here is my all code:
const genericPool = require("generic-pool");
const factory = {
create: function () {
console.log("factory create");
return null;
},
destroy: function () {
console.log("====> factory destroy");
return true;
}
};
const pool = genericPool.createPool(factory, {
max: 10, // maximum size of the pool
idleTimeoutMillis: 30000,
min: 2
});
function fetch(idx) {
return new Promise((resolve) => {
setTimeout(() => {
console.log(idx, "done");
resolve();
}, 1 * 1000);
});
}
let n = 0;
while (n < 20) {
((m) => {
pool
.acquire()
.then((client) => {
return fetch(m).then(() => {
console.log(m, "release");
return pool.release(client);
});
})
.catch(function (err) {
console.log("err=>", err);
});
})(n);
n++;
}
pool.drain().then(function () {
pool.clear();
});
"generic-pool": "^3.8.2"
Here is online demo
Metadata
Metadata
Assignees
Labels
No labels
