Skip to content

Commit

Permalink
Refactor: use async/await in closeResources() (#107)
Browse files Browse the repository at this point in the history
Category: fix
  • Loading branch information
vweevers authored Dec 31, 2024
1 parent a5c2e52 commit fdb7864
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions abstract-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,20 @@ class AbstractLevel extends EventEmitter {
// In parallel so that all resources know they are closed
const resources = Array.from(this.#resources)
const promises = resources.map(closeResource)

// TODO: async/await
return Promise.allSettled(promises).then(async (results) => {
const errors = []

for (let i = 0; i < results.length; i++) {
if (results[i].status === 'fulfilled') {
this.#resources.delete(resources[i])
} else {
errors.push(convertRejection(results[i].reason))
}
const results = await Promise.allSettled(promises)
const errors = []

for (let i = 0; i < results.length; i++) {
if (results[i].status === 'fulfilled') {
this.#resources.delete(resources[i])
} else {
errors.push(convertRejection(results[i].reason))
}
}

if (errors.length > 0) {
throw combineErrors(errors)
}
})
if (errors.length > 0) {
throw combineErrors(errors)
}
}

async _close () {}
Expand Down

0 comments on commit fdb7864

Please sign in to comment.