1

I was creating a program which should stop automatically a <b>. So please tell me how, here is a little bit I am thinking off:

var time = date.getTime();
var seconds = 0;
if (time + seconds == date.getTime())
{
// Stop everything i do by myself :)
}
vinS
  • 1,417
  • 5
  • 24
  • 37
modifyer
  • 67
  • 1
  • 2
  • 7

2 Answers2

4

Something like this:

var keepGoing = true;


setTimeout(function(){

    keepGoing = false;

}, 1000 * 60 * 60); //one hour


while(keepGoing){

    //stuff to do

}
Darin Cardin
  • 627
  • 1
  • 4
  • 10
0

We can use a combination of setInterval and setTimeout to accomplish this.

function doStuff(){
    //do whatever you need to do
}

var is_running = true;

setTimeout(function(){
    is_running = false; //Stop the program
}, 1000 * 60 * 60); //Do this after 1 hour

while(is_running){
    doStuff(); //whatever your function does
}
AksLolCoding
  • 157
  • 10