theflarenet
theflarenet

Reputation: 656

setTimeout reset for long durations

I have a setTimeout function that starts 25-minutes in and resets/restarts the next 25-minutes. My test script clearly works when I change it from 1500000ms to something shorter like 1000ms; however it does not when I (tediously) test it every 25-minutes (1500000ms). Any suggestions?

//    1000ms = 1s
//    60000ms = 60s         // 1 min
//    1500000 = 1500s       // 25 mins

var timer = null;
timer = setTimeout(sessionFunction, 1500000);

function sessionFunction() {
    alert('test');
    clearTimeout(timer); 

    timer = setTimeout(sessionFunction, 1500000);
}

//    1000ms = 1s
//    60000ms = 60s         // 1 min
//    1500000 = 1500s       // 25 mins

var timer = null;
timer = setTimeout(sessionFunction, 1500000);

function sessionFunction() {
    alert('test');
    clearTimeout(timer); 
    
    timer = setTimeout(sessionFunction, 1500000);
}

Upvotes: 0

Views: 934

Answers (1)

Red Puffle
Red Puffle

Reputation: 94

I suggest changing the script so that the timer fires every minute and keeps a counter of each time it fires. Once the counter hits 25 then you know 25 minutes have passed. The code won't be quite as simple, but it does avoid the issue you have encountered where the timer is not firing.

Upvotes: 1

Related Questions