gpt4 book ai didi

dart - dart计时器定期文档令人困惑

转载 作者:行者123 更新时间:2023-12-03 03:44:20 24 4
gpt4 key购买 nike

我的任务很长,我想在运行结束后的固定间隔内安排新的运行,我发现了这一点。以下是什么意思?特别是最后一段。

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.

最佳答案

假设您将计时器设置为每30秒运行一次。如果第二次调用该回调需要10秒才能完成,则对该回调的第三次调用可能是:

  • 在第二个 call 开始后30秒
  • 第二个通话结束后30秒(第二个通话开始后40秒,因为花费了10秒),所以
  • 计划第二个 call 运行30秒后(基于上述情况,可能已被延迟,例如,由于第一个 call 的持续时间)
  • 关于dart - dart计时器定期文档令人困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30434880/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com