Skip to content

Commit d60bbc9

Browse files
committed
Refactor: use async/await in closeResources()
Category: change
1 parent a05a8ea commit d60bbc9

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

abstract-level.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,20 @@ class AbstractLevel extends EventEmitter {
291291
// In parallel so that all resources know they are closed
292292
const resources = Array.from(this.#resources)
293293
const promises = resources.map(closeResource)
294-
295-
// TODO: async/await
296-
return Promise.allSettled(promises).then(async (results) => {
297-
const errors = []
298-
299-
for (let i = 0; i < results.length; i++) {
300-
if (results[i].status === 'fulfilled') {
301-
this.#resources.delete(resources[i])
302-
} else {
303-
errors.push(convertRejection(results[i].reason))
304-
}
294+
const results = await Promise.allSettled(promises)
295+
const errors = []
296+
297+
for (let i = 0; i < results.length; i++) {
298+
if (results[i].status === 'fulfilled') {
299+
this.#resources.delete(resources[i])
300+
} else {
301+
errors.push(convertRejection(results[i].reason))
305302
}
303+
}
306304

307-
if (errors.length > 0) {
308-
throw combineErrors(errors)
309-
}
310-
})
305+
if (errors.length > 0) {
306+
throw combineErrors(errors)
307+
}
311308
}
312309

313310
async _close () {}

0 commit comments

Comments
 (0)