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 * Serialize a series of asynchronous calls to a function
* over a list of objects * 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 = [] const results = []
return list.reduce((memo, item) => { for (const item of list) {
return memo.then(() => { results.push(await fn(item));
return fn(item) }
}).then(result => {
results.push(result) return results;
})
},
Promise.resolve()
).then(function() {
return results
})
} }
/** /**

Loading…
Cancel
Save