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

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

Issue 23793006: Handle Future result from Future.sync computation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nits from floitsch Created 7 years, 3 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
« no previous file with comments | « sdk/lib/async/future.dart ('k') | tests/lib/async/future_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 _FutureOnValue<T>(T value); 8 typedef dynamic _FutureOnValue<T>(T value);
9 typedef dynamic _FutureOnError(error); 9 typedef dynamic _FutureOnError(error);
10 /** Test used by [Future.catchError] to handle skip some errors. */ 10 /** Test used by [Future.catchError] to handle skip some errors. */
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 _FutureOnValue get _onValue => _isChained ? null : _onValueCallback; 136 _FutureOnValue get _onValue => _isChained ? null : _onValueCallback;
137 _FutureErrorTest get _errorTest => _isChained ? null : _errorTestCallback; 137 _FutureErrorTest get _errorTest => _isChained ? null : _errorTestCallback;
138 _FutureOnError get _onError => _isChained ? null : _onErrorCallback; 138 _FutureOnError get _onError => _isChained ? null : _onErrorCallback;
139 _FutureAction get _whenCompleteAction 139 _FutureAction get _whenCompleteAction
140 => _isChained ? null : _whenCompleteActionCallback; 140 => _isChained ? null : _whenCompleteActionCallback;
141 141
142 _Future() 142 _Future()
143 : _onValueCallback = null, _errorTestCallback = null, 143 : _onValueCallback = null, _errorTestCallback = null,
144 _onErrorCallback = null, _whenCompleteActionCallback = null; 144 _onErrorCallback = null, _whenCompleteActionCallback = null;
145 145
146 _Future.immediate(T value) 146 /// Valid types for value: `T` or `Future<T>`.
147 _Future.immediate(value)
147 : _onValueCallback = null, _errorTestCallback = null, 148 : _onValueCallback = null, _errorTestCallback = null,
148 _onErrorCallback = null, _whenCompleteActionCallback = null { 149 _onErrorCallback = null, _whenCompleteActionCallback = null {
149 _asyncComplete(value); 150 _asyncComplete(value);
150 } 151 }
151 152
152 _Future.immediateError(var error, [Object stackTrace]) 153 _Future.immediateError(var error, [Object stackTrace])
153 : _onValueCallback = null, _errorTestCallback = null, 154 : _onValueCallback = null, _errorTestCallback = null,
154 _onErrorCallback = null, _whenCompleteActionCallback = null { 155 _onErrorCallback = null, _whenCompleteActionCallback = null {
155 _asyncCompleteError(error, stackTrace); 156 _asyncCompleteError(error, stackTrace);
156 } 157 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // Two corner cases if the value is a future: 315 // Two corner cases if the value is a future:
315 // 1. the future is already completed and an error. 316 // 1. the future is already completed and an error.
316 // 2. the future is not yet completed but might become an error. 317 // 2. the future is not yet completed but might become an error.
317 // The first case means that we must not immediately complete the Future, 318 // The first case means that we must not immediately complete the Future,
318 // as our code would immediately start propagating the error without 319 // as our code would immediately start propagating the error without
319 // giving the time to install error-handlers. 320 // giving the time to install error-handlers.
320 // However the second case requires us to deal with the value immediately. 321 // However the second case requires us to deal with the value immediately.
321 // Otherwise the value could complete with an error and report an 322 // Otherwise the value could complete with an error and report an
322 // unhandled error, even though we know we are already going to listen to 323 // unhandled error, even though we know we are already going to listen to
323 // it. 324 // it.
325
326 // Assign to typed variables so we get earlier checks in checked mode.
327 if (value is Future) {
328 Future<T> typedFuture = value;
329 } else {
330 T typedValue = value;
331 }
332
324 if (value is Future && 333 if (value is Future &&
325 (value is! _Future || !(value as _Future)._isComplete)) { 334 (value is! _Future || !(value as _Future)._isComplete)) {
326 // Case 2 from above. We need to register. 335 // Case 2 from above. We need to register.
327 // Note that we are still completing asynchronously: either we register 336 // Note that we are still completing asynchronously: either we register
328 // through .then (in which case the completing is asynchronous), or we 337 // through .then (in which case the completing is asynchronous), or we
329 // have a _Future which isn't complete yet. 338 // have a _Future which isn't complete yet.
330 _complete(value); 339 _complete(value);
331 return; 340 return;
332 } 341 }
333 342
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 listener._setValue(listenerValueOrError); 515 listener._setValue(listenerValueOrError);
507 } else { 516 } else {
508 listeners = listener._removeListeners(); 517 listeners = listener._removeListeners();
509 listener._setError(listenerValueOrError); 518 listener._setError(listenerValueOrError);
510 } 519 }
511 // Prepare for next round. 520 // Prepare for next round.
512 source = listener; 521 source = listener;
513 } 522 }
514 } 523 }
515 } 524 }
OLDNEW
« 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