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

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

Issue 12224128: Pump the event queue manually rather than using a timer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Get rid of one more sleep call 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 | « no previous file | pkg/scheduled_test/test/metatest.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 d18b59ed7d997596e70387ef158c7563512f3aa6..bc7a7c5f97ab047634f68554c9dd74a5c286f90d 100644
--- a/pkg/scheduled_test/lib/src/utils.dart
+++ b/pkg/scheduled_test/lib/src/utils.dart
@@ -16,48 +16,3 @@ void chainToCompleter(Future future, Completer completer) {
/// Prepends each line in [text] with [prefix].
String prefixLines(String text, {String prefix: '| '}) =>
text.split('\n').map((line) => '$prefix$line').join('\n');
-
-/// Returns a [Future] that completes in at least [milliseconds].
-///
-/// This pumps the event loop after every millisecond of sleeping. This should
-/// ensure 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(1, (_) => completer.complete());
- return completer.future;
-}
-
-/// Wraps [input] to provide a timeout. If [input] completes before
-/// [milliseconds] have passed, then the return value completes in the same way.
-/// However, if [milliseconds] pass before [input] has completed, [onTimeout] is
-/// run and its result is passed to [input] (with chaining, if it returns a
-/// [Future]).
-///
-/// Note that timing out will not cancel the asynchronous operation behind
-/// [input].
-Future timeout(Future input, int milliseconds, onTimeout()) {
- bool completed = false;
- var completer = new Completer();
- var timer = new Timer(milliseconds, (_) {
- completed = true;
- chainToCompleter(new Future.immediate(null).then((_) => onTimeout()),
- completer);
- });
- input.then((value) {
- if (completed) return;
- timer.cancel();
- completer.complete(value);
- }).catchError((e) {
- if (completed) return;
- timer.cancel();
- completer.completeError(e.error, e.stackTrace);
- });
- return completer.future;
-}
« no previous file with comments | « no previous file | pkg/scheduled_test/test/metatest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698