Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call function once, then setInterval

I have a function that that I would like to call immediately, then use setInterval to update every ten seconds.

Currently I am using something like

myFunction();
setInterval(function(){
 myFunction();
}, 10000);

Is there a better way to do this? I feel like there should be a way to tell setInterval to fire on call, but I cannot seem to find anything on it.

like image 704
uberHasu Avatar asked Aug 31 '25 20:08

uberHasu


1 Answers

This isn't any "better," but it does what you want with fewer lines:

myFunction();
setInterval(myFunction, 10000);
like image 78
Bucket Avatar answered Sep 04 '25 21:09

Bucket