Index: pkg/scheduled_test/test/utils.dart |
diff --git a/pkg/scheduled_test/test/utils.dart b/pkg/scheduled_test/test/utils.dart |
index 42f5c22a9b1ae84010da2af1451a37460d822996..3d59e660b81a919beef9eb52700975860a46eedc 100644 |
--- a/pkg/scheduled_test/test/utils.dart |
+++ b/pkg/scheduled_test/test/utils.dart |
@@ -20,19 +20,16 @@ export 'package:scheduled_test/src/utils.dart'; |
/// 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(new Duration(milliseconds: milliseconds), () { |
- completed = true; |
- chainToCompleter(new Future.immediate(null).then((_) => onTimeout()), |
- completer); |
+ chainToCompleter(new Future.of(onTimeout), completer); |
}); |
input.then((value) { |
- if (completed) return; |
+ if (completer.isCompleted) return; |
timer.cancel(); |
completer.complete(value); |
}).catchError((e) { |
- if (completed) return; |
+ if (completer.isCompleted) return; |
timer.cancel(); |
completer.completeError(e.error, e.stackTrace); |
}); |