How to make setTimeout and setInterval work with large timeout values - good coders code, great reuse |
| How to make setTimeout and setInterval work with large timeout values Posted: 27 Oct 2015 08:05 PM PDT I just ran into a problem with I was writing an application that needed a 30+ day delay and my setTimeout(function () { alert("doesn't work - instant alert"); }, 30 * 24 * 3600 * 1000) // 30 days (more than 2^31-1 milliseconds) This doesn't work. Delay value overflows and I wrote my own function setTimeout_ (fn, delay) { var maxDelay = Math.pow(2,31)-1; if (delay > maxDelay) { var args = arguments; args[1] -= maxDelay; return setTimeout(function () { setTimeout_.apply(undefined, args); }, maxDelay); } return setTimeout.apply(undefined, arguments); } This function preserves I'll leave getting Until next time! |
| You are subscribed to email updates from good coders code, great reuse. To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
| Google Inc., 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States | |
No comments:
Post a Comment
Keep a civil tongue.