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

125
Views
Usando dos esperas en la función javascript, ambas llaman a la misma función para crear una promesa, el programa espera la primera espera pero no la segunda

He creado algunos cuadros emergentes de alerta/mensaje con await, async y una promesa. Para mostrar el cuadro emergente, llamo a la función para crear la promesa que también crea el cuadro emergente. La primera vez que se llama a la función para crear el cuadro emergente, todo funciona a la perfección. Sin embargo, la segunda vez, el código no espera el resultado del cuadro emergente, sino que sigue ejecutándose.

Por supuesto, quiero que el código espere a que termine la segunda llamada a ddaprompt() antes de continuar, pero no es así.

Sospecho que tiene algo que ver con usar la misma función para crear dos promesas o es casi como la segunda vez que se llama a la función de promesa, está duplicando la primera promesa junto con el hecho de que ya está resuelta y, por lo tanto, regresa de inmediato, o tal vez es con la secuencia de llamadas de función para llegar a donde se crea la promesa. Pero no sé.

Tenga en cuenta que hay algunos cuadros de alerta regulares de javascript que dicen lo que está sucediendo.

 async function ddaconfirm(content, addtxtbox, txtfrtxtbx) { var ddalertinterval; var promise = new Promise((resolve, reject) => { ddaalert(content + "<br style='line-height: 34px;'>" + ((addtxtbox) ? "<INPUT TYPE='text' id='USRRSPNSE' value=" + txtfrtxtbx + "><p></p>" : "") + confirmbuttons); if (addtxtbox) document.getElementById('USRRSPNSE').focus(); ddalertinterval = setInterval(function confirmresult() { if (buttonpressed != undefined || document.getElementById('POPUPBX').style.display == 'none') { if (buttonpressed == true && addtxtbox) buttonpressed = document.getElementById('USRRSPNSE').value; resolve(buttonpressed); } }, 100); }); var result = await promise; /* wait until the promise resolves*/ clearInterval(ddalertinterval); // ddaalert(result + " From Promise!"); // "done!" return result; } async function ddaprompt(content, defaulttxt) { return await ddaconfirm(content, true, defaulttxt); } async function testprompts() { var positiontoadd = await ddaprompt("Enter the number of the position of the column to add. Enter a number between 1 and <somenumber> " , "") -1; alert(positiontoadd); var texttoadd = await ddaprompt("Enter the title the new column should have, use CAPITALS, and a unique set of letters:", ""); alert(texttoadd + "Didn't wait for second ddaprompt to finish"); } testprompts();
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!