[我意识到在当前的Dart SDK版本0.4.1.0_r19425中,setTimeout
,setInterval
,clearTimeout
,clearInterval
之类的方法不再属于Window
类,它们都移至了Window
。现在有关于如何使用它们的任何文档吗?每次我想使用它们时都需要创建一个新的WorkerContext
实例吗?
除了克里斯提到的计时器,还有一个WorkerContext
API:
WorkerContext
尚不直接支持取消Future回调,但是效果很好:
Future-based
希望很快也会有var future = new Future.delayed(const Duration(milliseconds: 10), doStuffCallback);
。
摘自var future = new Future.delayed(const Duration(milliseconds: 10));
var subscription = future.asStream().listen(doStuffCallback);
// ...
subscription.cancel();
(2013年2月14日)。>>
Stream version of Timer.repeating还有另一个示例(从同一篇文章复制)
post on the group特别是,它们现在是
// Old Version window.setTimeout(() { doStuff(); }, 0); // New Version import 'dart:async'; Timer.run(doStuffCallback);
库中// Old version: var id = window.setTimeout(doStuffCallback, 10); .... some time later.... window.clearTimeout(id); id = window.setInterval(doStuffCallback, 1000); window.clearInterval(id); // New version: var timer = new Timer(const Duration(milliseconds: 10), doStuffCallback); ... some time later --- timer.cancel(); timer = new Timer.repeating(const Duration(seconds: 1), doStuffCallback); timer.cancel();
类的一部分(而不是Timer
,后者似乎是IndexedDb特定的)。dart:async
您可以使用: