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

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

Issue 9155017: Handle defered handling of exceptions (where the exception is thrown before the (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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 | no next file » | 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 bool get hasValue() { 79 bool get hasValue() {
80 return isComplete && _exception === null; 80 return isComplete && _exception === null;
81 } 81 }
82 82
83 void then(void onComplete(T value)) { 83 void then(void onComplete(T value)) {
84 if (hasValue) { 84 if (hasValue) {
85 onComplete(value); 85 onComplete(value);
86 } else if (!isComplete) { 86 } else if (!isComplete) {
87 _listeners.add(onComplete); 87 _listeners.add(onComplete);
88 } else if (!_exceptionHandled) {
Siggi Cherem (dart-lang) 2012/01/10 20:39:27 I believe we don't want to do this part of the cha
89 throw _exception;
90 } 88 }
91 } 89 }
92 90
93 void handleException(void onException(Object exception)) { 91 void handleException(void onException(Object exception)) {
94 _exceptionHandlers.add(onException); 92 if (null !== _exception) {
Siggi Cherem (dart-lang) 2012/01/10 20:39:27 (nit): keeping the style consistent with the rest
93 if (!_exceptionHandled) _exceptionHandled = onException(exception);
94 } else {
95 _exceptionHandlers.add(onException);
96 }
95 } 97 }
96 98
97 void _complete() { 99 void _complete() {
98 _isComplete = true; 100 _isComplete = true;
99 if (_exception !== null) { 101 if (_exception !== null) {
100 for (Function handler in _exceptionHandlers) { 102 for (Function handler in _exceptionHandlers) {
101 if (handler(_exception)) { 103 if (handler(_exception)) {
102 _exceptionHandled = true; 104 _exceptionHandled = true;
103 break; 105 break;
104 } 106 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 149 }
148 150
149 void complete(T value) { 151 void complete(T value) {
150 _futureImpl._setValue(value); 152 _futureImpl._setValue(value);
151 } 153 }
152 154
153 void completeException(var exception) { 155 void completeException(var exception) {
154 _futureImpl._setException(exception); 156 _futureImpl._setException(exception);
155 } 157 }
156 } 158 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698