I have a weird one I can't wrap my brains around.
const load = url => {
return new Promise( resolve => {
const img = new Image()
img.onload = () => resolve({ url, ratio: img.naturalWidth / img.naturalHeight })
img.src = url
})
}
How am I supposed to use async / await
given the onload is just a callback assignment ... I am stuck at the following:
const load = async url => {
const img = new Image()
img.src = url
return await img.onload = () => ({ url, ratio: img.naturalWidth / img.naturalHeight })
// cannot use await for img.onload obviously ..
// nor can I put await in the onload function ... since it's not going to do anything
}
Is it possible to solve without having to use the resolve method ?