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

107
Views
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
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!