Creates a new repeating timer.
The callback
is invoked repeatedly with duration
intervals until
canceled with the cancel function.
The exact timing depends on the underlying timer implementation.
No more than n
callbacks will be made in duration * n
time,
but the time between two consecutive callbacks
can be shorter and longer than duration
.
In particular, an implementation may schedule the next callback, e.g.,
a duration
after either when the previous callback ended,
when the previous callback started, or when the previous callback was
scheduled for - even if the actual callback was delayed.
Source
factory Timer.periodic(Duration duration, void callback(Timer timer)) { if (Zone.current == Zone.ROOT) { // No need to bind the callback. We know that the root's timer will // be invoked in the root zone. return Zone.current.createPeriodicTimer(duration, callback); } // TODO(floitsch): the return type should be 'void', and the type // should be inferred. var boundCallback = Zone.current .bindUnaryCallback<dynamic, Timer>(callback, runGuarded: true); return Zone.current.createPeriodicTimer(duration, boundCallback); }