blob: 1de955ae4ee9e9c1b638b0d5c737db8e775d4053 [file] [log] [blame]
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion factory Timer.periodic(Duration duration, void callback(Timer timer))
/// Creates a new repeating timer.
/// The callback is invoked repeatedly with duration intervals until canceled.
/// @description Checks that callback function is called repeatedly after
/// the given duration.
/// @author kaigorodov
import "dart:async";
import "../../../Utils/expect.dart";
main() {
int times = 10;
int count = 0;
Duration delay = durationMs(20);
Stopwatch sw = new Stopwatch();
new Timer.periodic(delay, (Timer timer) {
Duration expected = delay * count;
Duration actual = sw.elapsed;
Expect.isTrue(expected <= actual, "expected=$expected, actual=$actual");
if (count == times) {