Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active April 1, 2019 15:06
Show Gist options
  • Save gladchinda/7d7afc1b412146190905ac52208db177 to your computer and use it in GitHub Desktop.
Save gladchinda/7d7afc1b412146190905ac52208db177 to your computer and use it in GitHub Desktop.
const loadPhoto = photo_url =>
new Promise(resolve => {
const img = new Image();
img.addEventListener('load', () => {
resolve(img);
}, false);
img.addEventListener('error', () => {
const rejection = Promise.reject(new Error('Image could not be loaded.'));
resolve(rejection);
}, false);
img.src = photo_url;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment