diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-06-04 03:13:46 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-06-04 03:13:46 +0200 |
| commit | 94f083788d58bccb09f775ef731827d29d719d43 (patch) | |
| tree | 0bc188ef302ddfc69365521d743cb9f6293ab327 /app/client/util | |
| parent | 2f22fd5e4a558ed9b2379565be88b9d1e1b9b7c5 (diff) | |
promises progress
Diffstat (limited to 'app/client/util')
| -rw-r--r-- | app/client/util/index.js | 13 |
1 files changed, 13 insertions, 0 deletions
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.' } |
