diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart index 355cd4c7606..3e5dd58d50f 100644 --- a/sdk/lib/async/future.dart +++ b/sdk/lib/async/future.dart @@ -553,17 +553,15 @@ abstract class Future { * } * */ - // The `Function` below can stand for several types: - // - (dynamic) -> T - // - (dynamic, StackTrace) -> T - // - (dynamic) -> Future - // - (dynamic, StackTrace) -> Future + // The `Function` below stands for one of two types: + // - (dynamic) -> FutureOr + // - (dynamic, StackTrace) -> FutureOr // Given that there is a `test` function that is usually used to do an // `isCheck` we should also expect functions that take a specific argument. // Note: making `catchError` return a `Future` in non-strong mode could be // a breaking change. Future catchError(Function onError, - {bool test(Object error)}); + {bool test(Object error)}); /** * Register a function to be called when this future completes. @@ -785,7 +783,7 @@ abstract class Completer { * * All listeners on the future are informed about the value. */ - void complete([value]); + void complete([FutureOr value]); /** * Complete [future] with an error. @@ -827,5 +825,4 @@ void _completeWithErrorCallback(_Future result, error, stackTrace) { } /** Helper function that converts `null` to a [NullThrownError]. */ -Object _nonNullError(Object error) => - (error != null) ? error : new NullThrownError(); +Object _nonNullError(Object error) => error ?? new NullThrownError(); diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart index eb13318ef7f..844646bbd53 100644 --- a/sdk/lib/async/future_impl.dart +++ b/sdk/lib/async/future_impl.dart @@ -14,7 +14,7 @@ typedef _FutureAction(); abstract class _Completer implements Completer { final _Future future = new _Future(); - void complete([value]); + void complete([FutureOr value]); void completeError(Object error, [StackTrace stackTrace]) { error = _nonNullError(error); @@ -36,7 +36,7 @@ abstract class _Completer implements Completer { class _AsyncCompleter extends _Completer { - void complete([value]) { + void complete([FutureOr value]) { if (!future._mayComplete) throw new StateError("Future already completed"); future._asyncComplete(value); } @@ -47,7 +47,7 @@ class _AsyncCompleter extends _Completer { } class _SyncCompleter extends _Completer { - void complete([value]) { + void complete([FutureOr value]) { if (!future._mayComplete) throw new StateError("Future already completed"); future._complete(value); }