Pavel Ševčík
4 years ago
No known key found for this signature in database
GPG Key ID: D3B8A90B4072D9DB
1 changed files with
6 additions and
13 deletions
-
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; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|