From fa03e9300fdea8a7d055d80c83195bb85a81731e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0ev=C4=8D=C3=ADk?= Date: Tue, 23 Mar 2021 13:59:05 +0100 Subject: [PATCH] Better seriesCall --- lib/util.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/util.js b/lib/util.js index 5300fa5..8dc625e 100644 --- a/lib/util.js +++ b/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; } /**