mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Add promiseMapSettledWithLimit utility
GitOrigin-RevId: e34102de17f28e43deb383d630088c6e753e2ec1
This commit is contained in:
@@ -13,6 +13,7 @@ module.exports = {
|
|||||||
expressify,
|
expressify,
|
||||||
expressifyErrorHandler,
|
expressifyErrorHandler,
|
||||||
promiseMapWithLimit,
|
promiseMapWithLimit,
|
||||||
|
promiseMapSettledWithLimit,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -264,3 +265,19 @@ async function promiseMapWithLimit(concurrency, array, fn) {
|
|||||||
const limit = pLimit(concurrency)
|
const limit = pLimit(concurrency)
|
||||||
return await Promise.all(array.map(x => limit(() => fn(x))))
|
return await Promise.all(array.map(x => limit(() => fn(x))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map values in `array` with the async function `fn`
|
||||||
|
*
|
||||||
|
* Limit the number of unresolved promises to `concurrency`.
|
||||||
|
*
|
||||||
|
* @template T, U
|
||||||
|
* @param {number} concurrency
|
||||||
|
* @param {Array<T>} array
|
||||||
|
* @param {(T) => Promise<U>} fn
|
||||||
|
* @return {Promise<Array<PromiseSettledResult<U>>>}
|
||||||
|
*/
|
||||||
|
function promiseMapSettledWithLimit(concurrency, array, fn) {
|
||||||
|
const limit = pLimit(concurrency)
|
||||||
|
return Promise.allSettled(array.map(x => limit(() => fn(x))))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user