From 94f083788d58bccb09f775ef731827d29d719d43 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 4 Jun 2018 03:13:46 +0200 Subject: promises progress --- app/client/util/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'app/client/util/index.js') diff --git a/app/client/util/index.js b/app/client/util/index.js index 6ae1f64..75992d9 100644 --- a/app/client/util/index.js +++ b/app/client/util/index.js @@ -25,6 +25,19 @@ export function randrange(a,b){ return Math.random() * (b-a) + a } document.body.style.backgroundImage = 'linear-gradient(' + (randint(40)+40) + 'deg, #fde, #ffe)' +export const allProgress = (promises, progress_cb) => { + let d = 0; + progress_cb(0); + promises.forEach((p) => { + p.then((s) => { + d += 1 + progress_cb((d * 100) / promises.length, d, promises.length) + return s + }) + }) + return Promise.all(promises) +} + export function timeInSeconds(n){ return (n / 10).toFixed(1) + ' s.' } -- cgit v1.2.3-70-g09d2