setInterval(receiveComent, 1000) 

With this line, the receiveComent function will be called every second, how to make it to be called only when receiveComent has completely completed its work?

    1 answer 1

    Use setTimeout instead of setInterval:

     setTimeout(doit, 1000); function doit() { // TODO: ... setTimeout(doit, 1000); } 

    And re-charge the timer at the end of the code.