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

91
Views
React wait until all asynchronous functions finishes its execution

I have the below handleSubmit function which makes 3 calls for the handleRequest async function (common function used to fetch result). I want to wait until all 3 functions finishes execution and need to show a success message if all 03 executes successfully. How can I identify when the 03 executions finishes programatically?

const handleSubmit = () => {

    if (isTravelStatusChanged) {
        const body = {
            travel_id: xxx,
            status: xxx
        }

        handleRequest(editTravelStatus, "PUT", body, (data) => {
            let affectedRowCount = data.affectedRowCount ? data.affectedRowCount : 0
            if (affectedRowCount > 0) {
                console.log("Result 1")
            }
            else {
                setSnackbarData({ message: "Failed", open: true, severity: "error", onClose: onCloseSnackbar })

            }
        })

    }

    if (isTravelAgentChanged) {
        const body = {
            travel_id: xxx,
            travel_agent_id: xxx
        }

        handleRequest(editTravelAgent, "PUT", body, (data) => {
            let affectedRowCount = data.affectedRowCount ? data.affectedRowCount : 0
            if (affectedRowCount > 0) {
                console.log("Result 2")
            }
            else {
                setSnackbarData({ message: "Failed", open: true, severity: "error", onClose: onCloseSnackbar })

            }
        })
    }

    if(isVisaChanged) {
        const body = {
            travel_id: xxx,
            visa_id: xxx
        }

        handleRequest(editVisa, "PUT", body, (data) => {
            let affectedRowCount = data.affectedRowCount ? data.affectedRowCount : 0
            if (affectedRowCount > 0) {
                console.log("Result 3")
            }
            else {
                setSnackbarData({ message: "Failed", open: true, severity: "error", onClose: onCloseSnackbar })

            }
        })
    }

}
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!