setInterval(loadBuses, 5000)
setInterval(fn, ms) runs the function fn again and again, every ms milliseconds, for as long as the page is open.
<p id="seconds">0</p>
let secondsText = ez.dom.select('#seconds').at(0)
let seconds = 0
function tick() {
seconds = seconds + 1
secondsText.textContent = seconds
}
setInterval(tick, 1000)
After 3 seconds the page shows 3. 1000 milliseconds is one second, so 2000 is 2 seconds and 500 is half a second.
setInterval(tick, 1000) // correct
setInterval(tick(), 1000) // wrong: runs tick once, right now, and never again
setInterval waits first and runs after. To run right away too, call the function once yourself:
loadBuses()
setInterval(loadBuses, 5000)
An async function works the same way: give its name.