| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart core library. | 5 // Dart core library. |
| 6 | 6 |
| 7 class PromiseImpl<T> implements Promise<T> { | 7 class PromiseImpl<T> implements Promise<T> { |
| 8 | 8 |
| 9 // Enumeration of possible states: | 9 // Enumeration of possible states: |
| 10 static final int CREATED = 0; | 10 static final int CREATED = 0; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 _clearListeners(); | 154 _clearListeners(); |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| 160 void addCompleteHandler(void completeHandler(T result)) { | 160 void addCompleteHandler(void completeHandler(T result)) { |
| 161 if (_state == COMPLETE_NORMAL) { | 161 if (_state == COMPLETE_NORMAL) { |
| 162 completeHandler(_value); | 162 completeHandler(_value); |
| 163 } else if (!isDone()) { | 163 } else if (!isDone()) { |
| 164 if (_normalListeners == null) { | 164 if (_normalListeners === null) { |
| 165 _normalListeners = new Queue<Function>(); | 165 _normalListeners = new Queue<Function>(); |
| 166 } | 166 } |
| 167 _normalListeners.addLast(completeHandler); | 167 _normalListeners.addLast(completeHandler); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 void addErrorHandler(void errorHandler(err)) { | 171 void addErrorHandler(void errorHandler(err)) { |
| 172 if (_state == COMPLETE_ERROR) { | 172 if (_state == COMPLETE_ERROR) { |
| 173 errorHandler(_error); | 173 errorHandler(_error); |
| 174 } else if (!isDone()) { | 174 } else if (!isDone()) { |
| 175 if (_errorListeners == null) { | 175 if (_errorListeners === null) { |
| 176 _errorListeners = new Queue<Function>(); | 176 _errorListeners = new Queue<Function>(); |
| 177 } | 177 } |
| 178 _errorListeners.addLast(errorHandler); | 178 _errorListeners.addLast(errorHandler); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 void addCancelHandler(void cancelHandler()) { | 182 void addCancelHandler(void cancelHandler()) { |
| 183 if (isCancelled()) { | 183 if (isCancelled()) { |
| 184 cancelHandler(); | 184 cancelHandler(); |
| 185 } else if (!isDone()) { | 185 } else if (!isDone()) { |
| 186 if (_cancelListeners == null) { | 186 if (_cancelListeners === null) { |
| 187 _cancelListeners = new Queue<Function>(); | 187 _cancelListeners = new Queue<Function>(); |
| 188 } | 188 } |
| 189 _cancelListeners.addLast(cancelHandler); | 189 _cancelListeners.addLast(cancelHandler); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 // TODO(sigmund): consider adding to the API a method that does the following: | 193 // TODO(sigmund): consider adding to the API a method that does the following: |
| 194 // Promise chain(callback(T r)) { | 194 // Promise chain(callback(T r)) { |
| 195 // return then(callback).flatten(); | 195 // return then(callback).flatten(); |
| 196 // } | 196 // } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 return process(marshalled); | 372 return process(marshalled); |
| 373 }).flatten(); | 373 }).flatten(); |
| 374 } | 374 } |
| 375 | 375 |
| 376 Promise<SendPort> _promise; | 376 Promise<SendPort> _promise; |
| 377 static Map<SendPort, Dispatcher> _dispatchers; | 377 static Map<SendPort, Dispatcher> _dispatchers; |
| 378 | 378 |
| 379 } | 379 } |
| OLD | NEW |