Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can someone tell me why using this setInterval takes 15 seconds to start running and how to make it run without delay? It works well in repeating every 15 seconds like it should but I want to remove the start

function pollServer() {
    intervalId = window.setInterval(function ()  {
        callE();
        callA();
        callC();
        callB();
        callD();
        
     }, 15000);  
    
 }
 pollServer();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

To fix this, call the function before setting the interval like this:

function foo() {
    callE();
    callA();
    callC();
    callB();
    callD();
}
foo();
setInterval(foo, 15000);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...