Estoy luchando para encontrar una solución al siguiente problema.
Necesitamos enviar el formulario en nuestro sitio web, al enviar, el sitio web envía datos a Google y una vez que la función de Google devuelve los datos "procesados", el formulario debe enviarse.
Para asegurarnos de que el cliente no espere mucho, queríamos agregar un plan de respaldo: cuando Google no responde en 5 segundos, solo form.submit() y continúe.
Lamentablemente, esto no funciona muy bien, mi pregunta es, ¿sería posible reescribir este código para que funcione como:
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(); } }