mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
10 lines
380 B
JavaScript
10 lines
380 B
JavaScript
|
// run `fn` in serie for all values, and resolve with an array of the resultss
|
||
|
// inspired by https://stackoverflow.com/a/50506360/1314820
|
||
|
export function mapSeries(values, fn) {
|
||
|
return values.reduce((promiseChain, value) => {
|
||
|
return promiseChain.then(chainResults =>
|
||
|
fn(value).then(currentResult => [...chainResults, currentResult])
|
||
|
)
|
||
|
}, Promise.resolve([]))
|
||
|
}
|