当前位置: 动力学知识库 > 问答 > 编程问答 >

dart timer periodic documentation is confusing

问题描述:

I have a long running task and I would like to schedule a new run a fixed interval after the run ends and I found this. What does the following mean? In particular the last paragraph.

Timer.periodic(Duration duration, Function void callback(Timer timer))

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.

网友答案:

Let's say you set a timer to run every 30 seconds. If the second time the callback is called it takes 10 seconds to complete, the third call to the callback could be:

  • 30 seconds after the second call started
  • 30 seconds after the second call ended (which is 40s after the second call started, since it took 10 secs)
  • 30 seconds after the second call was scheduled to run (which based on the above, could have been delayed, eg. by the duration of the first call)
分享给朋友:
您可能感兴趣的文章:
随机阅读: