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

Side by Side Diff: sdk/lib/async/future_impl.dart

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.async; 5 part of dart.async;
6 6
7 deprecatedFutureValue(_FutureImpl future) => 7 deprecatedFutureValue(_FutureImpl future) =>
8 future._isComplete ? future._resultOrListeners : null; 8 future._isComplete ? future._resultOrListeners : null;
9 9
10 10
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 future.catchError(handleError).then((Object value) { 132 future.catchError(handleError).then((Object value) {
133 if (values == null) return null; 133 if (values == null) return null;
134 values[pos] = value; 134 values[pos] = value;
135 remaining--; 135 remaining--;
136 if (remaining == 0) { 136 if (remaining == 0) {
137 completer.complete(values); 137 completer.complete(values);
138 } 138 }
139 }); 139 });
140 } 140 }
141 if (remaining == 0) { 141 if (remaining == 0) {
142 return new Future.immediate(const []); 142 return new Future.value(const []);
143 } 143 }
144 values = new List(remaining); 144 values = new List(remaining);
145 completer = new Completer<List>(); 145 completer = new Completer<List>();
146 return completer.future; 146 return completer.future;
147 } 147 }
148 148
149 Future then(f(T value), { onError(AsyncError error) }) { 149 Future then(f(T value), { onError(AsyncError error) }) {
150 if (!_isComplete) { 150 if (!_isComplete) {
151 if (onError == null) { 151 if (onError == null) {
152 return new _ThenFuture(f).._subscribeTo(this); 152 return new _ThenFuture(f).._subscribeTo(this);
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 Future catchError(function(AsyncError error), {bool test(var error)}) { 526 Future catchError(function(AsyncError error), {bool test(var error)}) {
527 return _future.catchError(function, test: test); 527 return _future.catchError(function, test: test);
528 } 528 }
529 529
530 Future<T> whenComplete(action()) { 530 Future<T> whenComplete(action()) {
531 return _future.whenComplete(action); 531 return _future.whenComplete(action);
532 } 532 }
533 533
534 Stream<T> asStream() => new Stream.fromFuture(_future); 534 Stream<T> asStream() => new Stream.fromFuture(_future);
535 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698