diff --git a/lib/ManagedResources.js b/lib/ManagedResources.js index d6746af..cb482dd 100644 --- a/lib/ManagedResources.js +++ b/lib/ManagedResources.js @@ -36,10 +36,9 @@ module.exports = class ManagedResources { } async destroyIdleResources() { - const destroys = this.#list.map((managedResource, index) => { - if (!managedResource.isIdle()) return; - return this.destroy(managedResource.resource).then(() => this.#removeManagedResource(managedResource, index)); - }); + const destroys = this.#list.map((managedResource, index) => (managedResource.isIdle() + ? managedResource.destroy().then(() => this.#removeManagedResource(managedResource, index)) + : Promise.resolve())); return Promise.all(destroys); } @@ -62,7 +61,7 @@ module.exports = class ManagedResources { } hasIdleResources() { - return Boolean(this.getIdleManagedResource()); + return this.#list.some((managedResource) => managedResource.isIdle()); } getIdleManagedResource() { @@ -70,7 +69,7 @@ module.exports = class ManagedResources { } hasAcquiredResources() { - return Boolean(this.#list.find((managedResource) => managedResource.isAcquired())); + return this.#list.some((managedResource) => managedResource.isAcquired()); } hasSpareCapacity() {