| OLD | NEW |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // Dart core library. | 2 // Dart core library. |
| 3 | 3 |
| 4 class FutureImpl<T> implements Future<T> { | 4 class FutureImpl<T> implements Future<T> { |
| 5 | 5 |
| 6 bool _isComplete = false; | 6 bool _isComplete = false; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Value that was provided to this Future by the Completer | 9 * Value that was provided to this Future by the Completer |
| 10 */ | 10 */ |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 final res = new FutureImpl(); | 50 final res = new FutureImpl(); |
| 51 res._setValue(value); | 51 res._setValue(value); |
| 52 return res; | 52 return res; |
| 53 } | 53 } |
| 54 | 54 |
| 55 T get value { | 55 T get value { |
| 56 if (!isComplete) { | 56 if (!isComplete) { |
| 57 throw new FutureNotCompleteException(); | 57 throw new FutureNotCompleteException(); |
| 58 } | 58 } |
| 59 if (_exception !== null) { | 59 if (_exception !== null) { |
| 60 throw new FutureUnhandledException(_exception, stackTrace); | 60 throw _exception; |
| 61 } | 61 } |
| 62 return _value; | 62 return _value; |
| 63 } | 63 } |
| 64 | 64 |
| 65 Object get exception { | 65 Object get exception { |
| 66 if (!isComplete) { | 66 if (!isComplete) { |
| 67 throw new FutureNotCompleteException(); | 67 throw new FutureNotCompleteException(); |
| 68 } | 68 } |
| 69 return _exception; | 69 return _exception; |
| 70 } | 70 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 bool get hasValue { | 83 bool get hasValue { |
| 84 return isComplete && _exception === null; | 84 return isComplete && _exception === null; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void then(void onSuccess(T value)) { | 87 void then(void onSuccess(T value)) { |
| 88 if (hasValue) { | 88 if (hasValue) { |
| 89 onSuccess(value); | 89 onSuccess(value); |
| 90 } else if (!isComplete) { | 90 } else if (!isComplete) { |
| 91 _successListeners.add(onSuccess); | 91 _successListeners.add(onSuccess); |
| 92 } else if (!_exceptionHandled) { | 92 } else if (!_exceptionHandled) { |
| 93 throw new FutureUnhandledException(_exception, stackTrace); | 93 throw _exception; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 void handleException(bool onException(Object exception)) { | 97 void handleException(bool onException(Object exception)) { |
| 98 if (_exceptionHandled) return; | 98 if (_exceptionHandled) return; |
| 99 if (_isComplete) { | 99 if (_isComplete) { |
| 100 if (_exception != null) { | 100 if (_exception != null) { |
| 101 _exceptionHandled = onException(_exception); | 101 _exceptionHandled = onException(_exception); |
| 102 } | 102 } |
| 103 } else { | 103 } else { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 if (hasValue) { | 133 if (hasValue) { |
| 134 for (Function listener in _successListeners) { | 134 for (Function listener in _successListeners) { |
| 135 listener(value); | 135 listener(value); |
| 136 } | 136 } |
| 137 } else { | 137 } else { |
| 138 if (!_exceptionHandled && _successListeners.length > 0) { | 138 if (!_exceptionHandled && _successListeners.length > 0) { |
| 139 throw new FutureUnhandledException(_exception, stackTrace); | 139 throw _exception; |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 } finally { | 142 } finally { |
| 143 for (Function listener in _completionListeners) { | 143 for (Function listener in _completionListeners) { |
| 144 try { | 144 try { |
| 145 listener(this); | 145 listener(this); |
| 146 } catch (e) {} | 146 } catch (e) {} |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 } | 149 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 } | 261 } |
| 262 | 262 |
| 263 void complete(T value) { | 263 void complete(T value) { |
| 264 _futureImpl._setValue(value); | 264 _futureImpl._setValue(value); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void completeException(Object exception, [Object stackTrace]) { | 267 void completeException(Object exception, [Object stackTrace]) { |
| 268 _futureImpl._setException(exception, stackTrace); | 268 _futureImpl._setException(exception, stackTrace); |
| 269 } | 269 } |
| 270 } | 270 } |
| OLD | NEW |