Stopping a Node.js callback by clearing setInterval -
need call on situation. if have function:
var timerid; function playback(client,log){ if (timerid) clearinterval(timerid); timerid = setinterval(function(){ var buffer = [], numberofloglines = log.length; while(numberofloglines > 0){ var l = log.pop().trim(); // pull top buffer.push(l); if(l.split(",")[0] === "$timetosend"){ //flag timming signal client.send("{\"playback\":" + json.stringify(buffer) + "}"); break; } } },playbackspeed); }
and call
clearinterval(timerid)
at other point stop callback? trying create pause/play situation start playback again invoke playback(client,log) again restart. seems work but, wondering clearing interval stop callback. don't want create log jam case of heavy "pause/play" happy people.
a call clearinterval( timerid ) stop future calls anonymous function. if there previous calls of running, these finish.
Comments
Post a Comment