Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
La función asíncrona no espera a que se resuelva otra asíncrona

Admito que todavía no entiendo por completo la sincronización/promesas, como probablemente pueda deducir de mi código, pero ¿cómo se supone que debo hacer que mi función espere a checkImageRatio en esta circunstancia?

 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"); }

¿Por qué la prueba de imagen no se resuelve aquí?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!