Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Call multiple function functions periodically with different delays in react native

I need to call multiple functions periodically with different delays in react-native. For calling all functions periodically at once I could use –

const interval = setInterval(() => {
     function1();
     function2();
      ....
}, 2000);

But in my case I need to call function1 after every 2 seconds, function2 after every 5 seconds, function3 after every 3 seconds and so on.
Any help will be appreciated. Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Have you tried using multiple setIntervals in the same function and calling that function?

 const callIntervals = () =>{
    
  setInterval(() => {
    function1();
  }, 2000);

  setInterval(() => {
    function2();
  }, 5000);

  setInterval(() => {
    function3();
  }, 3000);
  
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading