Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: pkg/scheduled_test/lib/src/utils.dart

Issue 12217122: Re-submit r18349. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/scheduled_test/lib/src/schedule.dart ('k') | pkg/scheduled_test/test/scheduled_test_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/scheduled_test/lib/src/utils.dart
diff --git a/pkg/scheduled_test/lib/src/utils.dart b/pkg/scheduled_test/lib/src/utils.dart
index 94be7ef7dd6d5a9bf0748c42f482be75272d4eab..b5dedf05b1cc17ecf52e0f81ab75f35b6f52e8f8 100644
--- a/pkg/scheduled_test/lib/src/utils.dart
+++ b/pkg/scheduled_test/lib/src/utils.dart
@@ -17,10 +17,20 @@ void chainToCompleter(Future future, Completer completer) {
String prefixLines(String text, {String prefix: '| '}) =>
text.split('\n').map((line) => '$prefix$line').join('\n');
-/// Returns a [Future] that completes in [milliseconds].
+/// Returns a [Future] that completes in at least [milliseconds].
+///
+/// This pumps the event loop after every second of sleeping. This should ensure
Bob Nystrom 2013/02/12 00:35:19 second -> millisecond.
nweiz 2013/02/12 00:52:19 Done.
+/// that even if the CPU is pegged and code is running much slower than
+/// expected, the sleep will take longer than any non-sleep code that's running.
Future sleep(int milliseconds) {
+ if (milliseconds == 0) return new Future.immediate(null);
+ return _sleep1().then((_) => sleep(milliseconds - 1));
+}
+
+/// Returns a [Future] that completes in one millisecond.
+Future _sleep1() {
var completer = new Completer();
- new Timer(milliseconds, (_) => completer.complete());
+ new Timer(1, (_) => completer.complete());
return completer.future;
}
« no previous file with comments | « pkg/scheduled_test/lib/src/schedule.dart ('k') | pkg/scheduled_test/test/scheduled_test_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698