// source from https://stackoverflow.com/a/7445863/713573
const initialDelay = 5;
const exp = 2;
const maxDelay = 4000;
const myFunction = function() {
console.log('time: %s, delay: %s', Date.now(), delay);
delay *= exp;
if (delay > maxDelay) {
delay = initialDelay;
}
setTimeout(myFunction, delay);
}
let delay = initialDelay;
setTimeout(myFunction, delay);
Sample: function is called at exponential rate, till max maximum delay is reached.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.