0

What return does is sending me to the beginning of the function. However it is useless for me. I am running the function every 30 seconds with an Interval. So it keeps running where I need it to run every 30 seconds for once.

And as far as I know break isn't helping either, it is breaking the loop but still processing the rest of codes.

So is there a function or code where it kills function totally until I recall it?

Thanks for your time!

Edit: After requets.

Edit 2: To be clear, stopping an Interval isn't what I need.

So here is an example of mine. What I need on this code is checking for error every 15 second. But what does this code is checking error and if it gets error it is checking again.

        setInterval(checkError, 15000);
        
        function checkError() {
    if (err) {
                    console.log(err);
                    return;
                }
        }

1 Answers1

1

The return statement never takes you to the beginning of the function. What happens here is that you don't stop the setInterval function calling your checkError function again.

Please use clearInterval to stop the recurring of this whenever you want - in this case when an error is found.

var interval = setInterval(checkError, 15000);

function checkError() {
   if (err) {
      console.log(err);
      clearInterval(interval);   //Stop the recurring here
   }
}
Charlie
  • 22,886
  • 11
  • 59
  • 90