Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
Async function not waiting for other async to resolve

I admit that I still do not fully fathom async/promises as you can probably gather from my code but how am I supposed to get my function to wait for checkImageRatio in this circumstance.

async function checkImageRatio(id){
    let myPromise = new Promise(function(resolve) {
        let test = false;
        $(`#image-${id}`).find('img').each(async function(){
            let img = new Image();

            img.src = this.src;
            await img.decode();

            console.log((img.width/img.height));

            if(Math.abs(1 - img.width/img.height) > 0.02){
                $(`#image-${id}-main-image`).css('border', '1px red solid');
                $(`#${id}-warning`).effect('shake', {distance: 8, times: 2}, 200);
                test = true;
            }
        });
        resolve(test); 
    })
}

async function saveProduct(id){
  var imageTest = await checkImageRatio(id).then(result=>{return result});
  console.log(imageTest);
  console.log("here");
}

Why is image test not resolving here??

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda