Skip to content

Instantly share code, notes, and snippets.

@gsimone
Created May 4, 2018 11:56
Show Gist options
  • Save gsimone/2c93686c8505b277898c184be47c300c to your computer and use it in GitHub Desktop.
Save gsimone/2c93686c8505b277898c184be47c300c to your computer and use it in GitHub Desktop.
Wait for all images
const images = ['http://picsum.photos/300/300?r&a=1', 'http://picsum.photos/300/300?r&a=2', 'http://picsum.photos/300/300?r&a=3']
const imageLoadPromise = (src) => new Promise((resolve, reject) => {
const img = new Image()
img.onload = resolve
img.src = src
})
Promise.all(images.map(imageLoadPromise))
.then(() => console.log('all done'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment