Correctly apply image timeout for loading images

This commit is contained in:
MoyuScript
2017-08-18 21:53:42 +08:00
parent dd24e7fa80
commit 0d127c0121
2 changed files with 12 additions and 3 deletions

View File

@@ -78,10 +78,12 @@ export default class ImageLoader<T> {
}
}
};
xhr.ontimeout = () => reject(`Timed out fetching ${src}`);
xhr.responseType = 'blob';
if (this.options.imageTimeout) {
xhr.timeout = this.options.imageTimeout;
const timeout = this.options.imageTimeout;
xhr.timeout = timeout;
xhr.ontimeout = () =>
reject(__DEV__ ? `Timed out (${timeout}ms) fetching ${src}` : '');
}
xhr.open('GET', src, true);
xhr.send();
@@ -122,6 +124,13 @@ export default class ImageLoader<T> {
resolve(img);
}, 500);
}
if (this.options.imageTimeout) {
const timeout = this.options.imageTimeout;
setTimeout(
() => reject(__DEV__ ? `Timed out (${timeout}ms) fetching ${src}` : ''),
timeout
);
}
});
this.cache[key] =