Question

I am calling a function recursively and in that function I am requesting update info from my server.

This is the calling function:

    function StartFeedUp() {
        GetNextImage();
        if (tmrStartFeedUp) window.clearTimeout(tmrStartFeedUp);
        tmrStartFeedUp = setTimeout(StartFeedUp, 100);
    }

This is the function being called:

            var urlTS = '/Cloud/isNewFrames.ashx?alias=' + alias + '&version=' + version + '&guidlogon=' + guidlogon;
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("POST", urlTS, true);
            xmlhttp.send();
            var nextts = xmlhttp.responseText;
            //do something with info

when the time limit of 100ms is reached is the XMLHttpRequest aborted or should I also use a timeout on the rest call?

Was it helpful?

Solution

clearTimeout will just prevent the function from being called again. It should not prevent any actions taken within. With that said, clearTimeout does not seem very useful in your case. It looks like you chain the setTimeout calls one after the other, and in this case clearTimeout is useless because when you enter the function the timeout is already cleared.

In your case I would suggest using setInterval instead of setTimeout, and call clearInterval to interrupt the function calls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top