开发者

Stopping a Node.js callback by clearing setInterval

Need a call on this situation. If I have this 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 from the top
            buffer.push(l);
            if(l.split(",")[0] === "$TIMETOSEND"){ //flag for the timming signal
                client.send("{\"playback\":" + JSON.stringify(buffer) + "}");
                break;
            }
        }
    },playBackSpeed);
}

and call

clearInterval(timerID)

at some other point does this stop the callback? I am trying to create a pause/play situation which to start the playBack again I would invoke the playBack(client,log) ag开发者_JAVA技巧ain to restart. Seems to work but, I am wondering does clearing the interval stop the callBack. I don't want to create a log jam for the case of the heavy "pause/play" happy people.


A call to clearInterval( timerID ) will stop any future calls to your anonymous function. If there are previous calls of it running, then these will finish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜