Files
manyplug/node_modules/fs-extra/lib/util/async.js
synt-xerror bbc44bec52 feat: initial CLI structure
- init: create plugin boilerplate
- install: install from local path with deps
- list: show installed plugins
- validate: check manyplug.json syntax
2026-04-09 01:15:00 -03:00

30 lines
806 B
JavaScript

'use strict'
// https://github.com/jprichardson/node-fs-extra/issues/1056
// Performing parallel operations on each item of an async iterator is
// surprisingly hard; you need to have handlers in place to avoid getting an
// UnhandledPromiseRejectionWarning.
// NOTE: This function does not presently handle return values, only errors
async function asyncIteratorConcurrentProcess (iterator, fn) {
const promises = []
for await (const item of iterator) {
promises.push(
fn(item).then(
() => null,
(err) => err ?? new Error('unknown error')
)
)
}
await Promise.all(
promises.map((promise) =>
promise.then((possibleErr) => {
if (possibleErr !== null) throw possibleErr
})
)
)
}
module.exports = {
asyncIteratorConcurrentProcess
}