overleaf/services/web/frontend/js/infrastructure/promise.js
Alexandre Bourdin a4a5a08c31 Merge pull request #14256 from overleaf/ab-unmanaged-remove-from-group-dropdown-action
[web] Add Remove from group action in dropdown for unmanaged/pending users

GitOrigin-RevId: daa66598e42befa2f8430bdf118e907a8758d60e
2023-08-23 08:05:10 +00:00

16 lines
570 B
JavaScript

/**
* run `fn` in serie for all values, and resolve with an array of the results
* inspired by https://stackoverflow.com/a/50506360/1314820
* @template T the input array's item type
* @template V the `fn` function's return type
* @param {T[]} values
* @param {(item: T) => Promise<V>} fn
* @returns {V[]}
*/
export function mapSeries(values, fn) {
return values.reduce(async (promiseChain, value) => {
const chainResults = await promiseChain
const currentResult = await fn(value)
return [...chainResults, currentResult]
}, Promise.resolve([]))
}