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.
CodePudding user response:
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);
}