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

94
Views
Multiple apis trigger without using settimeout

I have calling dataUpdate function every 4 second until records length to 0.

Inside the dataUpdate this.callAPI(); is trigger api call.

I set manual timeout for 4 seconds to call the function to callapi.

Instead of timeout ,how to call the api immediately after previous api completed.

 dataUpdate =()=> { 
     var arrayList = this.arrayList; 
     if(arrayList.length > 0)
     { 
         var inputData = {
             ...inputData,
             data:{
                 ...inputData.data,first:'',second:'' 
             }
          }; 
            var first = arrayList[0].first;
            var second = arrayList[0].second; 
            inputData.data.first = first;
            inputData.data.second = second;  
            this.setState({ inputData:inputData });  
            this.callAPI(); 
            arrayList.shift();
            this.arrayList = arrayList; 
            
                if(arrayList.length !== 0){  
                    setTimeout(() => { 
                         this.dataUpdate();
                    }, 4000); 
                } 
                
                if(arrayList.length === 0){   
                    setTimeout(() => {  
                        this.props.callMessage(this.totalCount);
                    }, 1000);    
                }
                 
       } 
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your problem is in having state. Make callapi function stateless and pass all needed parameters so you can call it any amount of times and do not rely on previous call or state

about 4 years ago · Juan Pablo Isaza Report
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!