diff options
Diffstat (limited to 'animism-align/frontend/app/utils')
| -rw-r--r-- | animism-align/frontend/app/utils/image.utils.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/animism-align/frontend/app/utils/image.utils.js b/animism-align/frontend/app/utils/image.utils.js index dced2d8..d7b7508 100644 --- a/animism-align/frontend/app/utils/image.utils.js +++ b/animism-align/frontend/app/utils/image.utils.js @@ -4,14 +4,15 @@ export const preloadImages = urls => batchPromise(urls, 4, preloadImage) export const batchPromise = (list, count, fn) => { // console.log(list, count, fn) - return new Promise((resolve, reject) => { + let cancelled = false + const promise = new Promise((resolve, reject) => { let index = 0 let len = list.length const worker = j => ( new Promise(resolveWorker => { const next = () => { const i = index++ - if (i >= len) { + if (cancelled || i >= len) { return resolveWorker() } const item = list[i] @@ -34,6 +35,10 @@ export const batchPromise = (list, count, fn) => { .then(resolve) .catch(reject) }) + const cancel = () => cancelled = true + return { + promise, cancel + } } export const preloadImage = (url, anonymous=false) => ( |
