| OLD | NEW |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { | 88 } else if (!_exceptionHandled) { |
| 89 throw _exception; | 89 throw _exception; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 void handleException(void onException(Object exception)) { | 93 void handleException(void onException(Object exception)) { |
| 94 _exceptionHandlers.add(onException); | 94 if (_exception !== null) { |
| 95 if (!_exceptionHandled) { |
| 96 _exceptionHandled = onException(exception); |
| 97 } |
| 98 } else { |
| 99 _exceptionHandlers.add(onException); |
| 100 } |
| 95 } | 101 } |
| 96 | 102 |
| 97 void _complete() { | 103 void _complete() { |
| 98 _isComplete = true; | 104 _isComplete = true; |
| 99 if (_exception !== null) { | 105 if (_exception !== null) { |
| 100 for (Function handler in _exceptionHandlers) { | 106 for (Function handler in _exceptionHandlers) { |
| 101 if (handler(_exception)) { | 107 if (handler(_exception)) { |
| 102 _exceptionHandled = true; | 108 _exceptionHandled = true; |
| 103 break; | 109 break; |
| 104 } | 110 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 153 } |
| 148 | 154 |
| 149 void complete(T value) { | 155 void complete(T value) { |
| 150 _futureImpl._setValue(value); | 156 _futureImpl._setValue(value); |
| 151 } | 157 } |
| 152 | 158 |
| 153 void completeException(var exception) { | 159 void completeException(var exception) { |
| 154 _futureImpl._setException(exception); | 160 _futureImpl._setException(exception); |
| 155 } | 161 } |
| 156 } | 162 } |
| OLD | NEW |