Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions src/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,9 @@ export class Pool<T> {
return reflect(
Promise.all(this.pendingCreates.map(create => reflect(create.promise)))
.then(() => {
// poll every 100ms and wait that all validations are ready
return new Promise((resolve, reject) => {
if (this.numPendingValidations() === 0) {
resolve();
return;
}
const interval = setInterval(() => {
if (this.numPendingValidations() === 0) {
clearInterval(interval);
resolve();
}
}, 100);
});
return Promise.all(
this.pendingValidations.map(validation => reflect(validation.promise))
);
})
.then(() => {
// Wait for all the used resources to be freed.
Expand Down
25 changes: 25 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,31 @@ describe('Tarn', () => {
expect(resources[3].destroyed).to.be.ok();
});
});
it('should destroy immediately if there are no async validations', done => {
pool = new Pool({
create: () => {
return Promise.resolve({});
},
destroy(res) {
return Promise.resolve({});
},
validate(res) {
return true;
},
reapIntervalMillis: 10,
idleTimeoutMillis: 1,
min: 0,
max: 10
});
let destroyed = false;
setImmediate(() => {
expect(destroyed).to.equal(true);
done();
});
pool.destroy().then(() => {
destroyed = true;
});
});
});

describe('acquireTimeout', () => {
Expand Down