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

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

Issue 2647833002: fix #28008, fix #28009 implement FutureOr<T> (Closed)
Patch Set: Merge remote-tracking branch 'origin/master' into 28008_futureort Created 3 years, 10 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
« no previous file with comments | « sdk/lib/async/future.dart ('k') | tests/lib/async/future_or_bad_type_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** The onValue and onError handlers return either a value or a future */ 7 /** The onValue and onError handlers return either a value or a future */
8 typedef dynamic/*T|Future<T>*/ _FutureOnValue<S, T>(S value); 8 typedef dynamic/*T|Future<T>*/ _FutureOnValue<S, T>(S value);
9 /** Test used by [Future.catchError] to handle skip some errors. */ 9 /** Test used by [Future.catchError] to handle skip some errors. */
10 typedef bool _FutureErrorTest(var error); 10 typedef bool _FutureErrorTest(var error);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 bool get _isComplete => _state >= _VALUE; 224 bool get _isComplete => _state >= _VALUE;
225 bool get _hasError => _state == _ERROR; 225 bool get _hasError => _state == _ERROR;
226 226
227 void _setChained(_Future source) { 227 void _setChained(_Future source) {
228 assert(_mayAddListener); 228 assert(_mayAddListener);
229 _state = _CHAINED; 229 _state = _CHAINED;
230 _resultOrListeners = source; 230 _resultOrListeners = source;
231 } 231 }
232 232
233 Future<E> then<E>( 233 Future<E> then<E>(
234 dynamic/*E|Future<E>*/ f(T value), { Function onError }) { 234 FutureOr<E> f(T value), { Function onError }) {
235 Zone currentZone = Zone.current; 235 Zone currentZone = Zone.current;
236 ZoneUnaryCallback registered; 236 ZoneUnaryCallback registered;
237 if (!identical(currentZone, _ROOT_ZONE)) { 237 if (!identical(currentZone, _ROOT_ZONE)) {
238 f = currentZone.registerUnaryCallback<dynamic, T>(f); 238 f = currentZone.registerUnaryCallback<FutureOr<E>, T>(f);
239 if (onError != null) { 239 if (onError != null) {
240 onError = _registerErrorHandler<T>(onError, currentZone); 240 onError = _registerErrorHandler<T>(onError, currentZone);
241 } 241 }
242 } 242 }
243 return _thenNoZoneRegistration<E>(f, onError); 243 return _thenNoZoneRegistration<E>(f, onError);
244 } 244 }
245 245
246 // This method is used by async/await. 246 // This method is used by async/await.
247 Future<E> _thenNoZoneRegistration<E>(f(T value), Function onError) { 247 Future<E> _thenNoZoneRegistration<E>(f(T value), Function onError) {
248 _Future<E> result = new _Future<E>(); 248 _Future<E> result = new _Future<E>();
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 737 }
738 }, onError: (e, s) { 738 }, onError: (e, s) {
739 if (timer.isActive) { 739 if (timer.isActive) {
740 timer.cancel(); 740 timer.cancel();
741 result._completeError(e, s); 741 result._completeError(e, s);
742 } 742 }
743 }); 743 });
744 return result; 744 return result;
745 } 745 }
746 } 746 }
OLDNEW
« no previous file with comments | « sdk/lib/async/future.dart ('k') | tests/lib/async/future_or_bad_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698