Chromium Code Reviews| 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; |
| } |