| 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..d18b59ed7d997596e70387ef158c7563512f3aa6 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 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(milliseconds, (_) => completer.complete());
|
| + new Timer(1, (_) => completer.complete());
|
| return completer.future;
|
| }
|
|
|
|
|