I want to run a particular function every 5 minutes. If I write code like this:
function f() {
console.log("hi");
d3.timer(f, 5*60*1000);
return true;
}
d3.timer(f, 5*60*1000);
then f seems to run once and then never again.
I achieved the desired behavior by creating a clone of f called f2: f calls d3.timer(f2) and f2 call d3.timer(f). This seems like an ugly hack. Is there a better way?
This sounds like a job for the standard JavaScript
setInterval()method:If you need it to run an animation at each invocation, that’s where
d3.timerwould be useful – otherwise, the standardsetIntervalandsetTimeoutmethods are likely to be easier.