Browse Source

Better seriesCall

umbrel
Pavel Ševčík 4 years ago
parent
commit
fa03e9300f
No known key found for this signature in database GPG Key ID: D3B8A90B4072D9DB
  1. 19
      lib/util.js

19
lib/util.js

@ -70,22 +70,15 @@ class Util {
/**
* Serialize a series of asynchronous calls to a function
* over a list of objects
* ref: http://www.joezimjs.com/javascript/patterns-asynchronous-programming-promises/
*/
static seriesCall(list, fn) {
static async seriesCall(list, fn) {
const results = []
return list.reduce((memo, item) => {
return memo.then(() => {
return fn(item)
}).then(result => {
results.push(result)
})
},
Promise.resolve()
).then(function() {
return results
})
for (const item of list) {
results.push(await fn(item));
}
return results;
}
/**

Loading…
Cancel
Save