blob: f3a7d4b0609027a203b0b3b82b9ef56d8da15b65 [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.
// @dart = 2.9
/// @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();
sw.start();
asyncStart();
new Timer.periodic(delay, (Timer timer) {
count++;
Duration expected = delay * count;
Duration actual = sw.elapsed;
Expect.isTrue(expected<=actual, "expected=$expected, actual=$actual");
if (count==times) {
timer.cancel();
asyncEnd();
}
});
}