A memo about sample code that executes at regular intervals while stopping after a certain amount of time in JavaScript.
Implemented using setInterval and clearInterval.
An example that logs every 0.2 seconds and stops after 10 seconds:
var refreshIntervalId = setInterval(function(){ console.log('y'); } , 200);
setTimeout(function(){ clearInterval(refreshIntervalId); } ,10000) ;