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

Unified Diff: sdk/lib/async/future_impl.dart

Issue 2790663003: Use FutureOr more and make Future.sync return the resulting Future directly. (Closed)
Patch Set: State that doWhile completes with null. Created 3 years, 9 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 | « sdk/lib/async/future.dart ('k') | tests/lib/async/future_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/future_impl.dart
diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart
index 325c5d715b457ec34f884e70835fb7e04026ca5f..14bac61ce77aeb5293a51c7d00c05f6ef4378dc9 100644
--- a/sdk/lib/async/future_impl.dart
+++ b/sdk/lib/async/future_impl.dart
@@ -207,15 +207,19 @@ class _Future<T> implements Future<T> {
// This constructor is used by async/await.
_Future();
- /// Valid types for value: `T` or `Future<T>`.
- _Future.immediate(value) {
- _asyncComplete(value);
+ _Future.immediate(FutureOr<T> result) {
+ _asyncComplete(result);
}
_Future.immediateError(var error, [StackTrace stackTrace]) {
_asyncCompleteError(error, stackTrace);
}
+ /** Creates a future that is already completed with the value. */
+ _Future.value(T value) {
+ _setValue(value);
+ }
+
bool get _mayComplete => _state == _INCOMPLETE;
bool get _isPendingComplete => _state == _PENDING_COMPLETE;
bool get _mayAddListener => _state <= _PENDING_COMPLETE;
@@ -496,23 +500,7 @@ class _Future<T> implements Future<T> {
// it.
if (value is Future<T>) {
- if (value is _Future<T>) {
- if (value._hasError) {
- // Case 1 from above. Delay completion to enable the user to register
- // callbacks.
- _setPendingComplete();
- _zone.scheduleMicrotask(() {
- _chainCoreFuture(value, this);
- });
- } else {
- _chainCoreFuture(value, this);
- }
- } else {
- // Case 2 from above. Chain the future immediately.
- // Note that we are still completing asynchronously (through
- // _chainForeignFuture).
- _chainForeignFuture(value, this);
- }
+ _chainFuture(value);
return;
}
T typedValue = value as Object/*=T*/;
@@ -523,6 +511,23 @@ class _Future<T> implements Future<T> {
});
}
+ void _chainFuture(Future<T> value) {
+ if (value is _Future<T>) {
+ if (value._hasError) {
+ // Delay completion to allow the user to register callbacks.
+ _setPendingComplete();
+ _zone.scheduleMicrotask(() {
+ _chainCoreFuture(value, this);
+ });
+ } else {
+ _chainCoreFuture(value, this);
+ }
+ return;
+ }
+ // Just listen on the foreign future. This guarantees an async delay.
+ _chainForeignFuture(value, this);
+ }
+
void _asyncCompleteError(error, StackTrace stackTrace) {
assert(!_isComplete);
« no previous file with comments | « sdk/lib/async/future.dart ('k') | tests/lib/async/future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698