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

Side by Side Diff: corelib/src/implementation/future_implementation.dart

Issue 9533014: futures: handle exceptions immediately if the future already completed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/corelib/src/FutureTest.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 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // Dart core library. 2 // Dart core library.
3 3
4 /** 4 /**
5 * Thrown if client tries to obtain value or exception 5 * Thrown if client tries to obtain value or exception
6 * before a future has completed. 6 * before a future has completed.
7 */ 7 */
8 class FutureNotCompleteException implements Exception { 8 class FutureNotCompleteException implements Exception {
9 FutureNotCompleteException() {} 9 FutureNotCompleteException() {}
10 String toString() => "Exception: future has not been completed"; 10 String toString() => "Exception: future has not been completed";
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 void then(void onComplete(T value)) { 87 void then(void onComplete(T value)) {
88 if (hasValue) { 88 if (hasValue) {
89 onComplete(value); 89 onComplete(value);
90 } else if (!isComplete) { 90 } else if (!isComplete) {
91 _listeners.add(onComplete); 91 _listeners.add(onComplete);
92 } else if (!_exceptionHandled) { 92 } else if (!_exceptionHandled) {
93 throw _exception; 93 throw _exception;
94 } 94 }
95 } 95 }
96 96
97 void handleException(void onException(Object exception)) { 97 void handleException(bool onException(Object exception)) {
98 _exceptionHandlers.add(onException); 98 if (_exceptionHandled) return;
99 if (_isComplete) {
100 if (_exception != null) {
101 _exceptionHandled = onException(_exception);
102 }
103 } else {
104 _exceptionHandlers.add(onException);
105 }
99 } 106 }
100 107
101 void _complete() { 108 void _complete() {
102 _isComplete = true; 109 _isComplete = true;
103 if (_exception !== null) { 110 if (_exception !== null) {
104 for (Function handler in _exceptionHandlers) { 111 for (Function handler in _exceptionHandlers) {
105 if (handler(_exception)) { 112 if (handler(_exception)) {
106 _exceptionHandled = true; 113 _exceptionHandled = true;
107 break; 114 break;
108 } 115 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 200 }
194 201
195 void complete(T value) { 202 void complete(T value) {
196 _futureImpl._setValue(value); 203 _futureImpl._setValue(value);
197 } 204 }
198 205
199 void completeException(var exception) { 206 void completeException(var exception) {
200 _futureImpl._setException(exception); 207 _futureImpl._setException(exception);
201 } 208 }
202 } 209 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/src/FutureTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698