Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
Js async wait for return

I am strugling to find a solution to the following problem.

We need to submit the form on our website, on submit, the website sends data to google and once the google function returns the data was "processed", the form should submit.

To make sure the customer does not wait for ages, we wanted to add a backup plan - when google does not reply in 5 seconds, just form.submit() and move on.

Sadly this does not work very well, my question is, would it be possible to rewrite this code to work like:

  1. send data to google and also wait for 5s
  2. No matter which of these events come first, await the return value and move on.
let formSubmitted = false;
function onCheckout(form) {
      setTimeout(() => {
          submitForm(form)
      }, "5000");
      sendToGoogle(submitForm(form)); 
      //send data to google, run submitForm() on callback, this is just simplified function
      
     // here I would like to return the value of formSubmitted, after max 5s.

    }

    function submitForm(form) {
        if (!formSubmitted) {
            formSubmitted = true;
            form.submit();
        }
    }

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda