| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 get local() { | 300 get local() { |
| 301 if (_dispatchers !== null) { | 301 if (_dispatchers !== null) { |
| 302 Dispatcher dispatcher = _dispatchers[_promise.value]; | 302 Dispatcher dispatcher = _dispatchers[_promise.value]; |
| 303 if (dispatcher !== null) return dispatcher.target; | 303 if (dispatcher !== null) return dispatcher.target; |
| 304 } | 304 } |
| 305 throw new Exception("Cannot access object of non-local proxy."); | 305 throw new Exception("Cannot access object of non-local proxy."); |
| 306 } | 306 } |
| 307 | 307 |
| 308 void send(List message) { | 308 void send(List message) { |
| 309 _marshal(message, (List marshalled) { | 309 _marshal(message, (List marshalled) { |
| 310 SendPortImpl port = _promise.value; | 310 SendPort port = _promise.value; |
| 311 port._sendNow(marshalled, null); | 311 port.send(marshalled, null); |
| 312 }); | 312 }); |
| 313 } | 313 } |
| 314 | 314 |
| 315 Promise call(List message) { | 315 Promise call(List message) { |
| 316 return _marshal(message, (List marshalled) { | 316 return _marshal(message, (List marshalled) { |
| 317 // TODO(kasperl): For now, the [Promise.then] implementation allows | 317 // TODO(kasperl): For now, the [Promise.then] implementation allows |
| 318 // me to return a promise and it will do the promise chaining. | 318 // me to return a promise and it will do the promise chaining. |
| 319 final result = new Promise(); | 319 final result = new Promise(); |
| 320 // The promise queue implementation guarantees that promise is | 320 // The promise queue implementation guarantees that promise is |
| 321 // resolved at this point. | 321 // resolved at this point. |
| 322 SendPortImpl outgoing = _promise.value; | 322 SendPort outgoing = _promise.value; |
| 323 ReceivePort incoming = outgoing._callNow(marshalled); | 323 ReceivePort incoming = outgoing.call(marshalled); |
| 324 incoming.receive((List receiveMessage, replyTo) { | 324 incoming.receive((List receiveMessage, replyTo) { |
| 325 result.complete(receiveMessage[0]); | 325 result.complete(receiveMessage[0]); |
| 326 }); | 326 }); |
| 327 return result; | 327 return result; |
| 328 }); | 328 }); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Marshal the [message] and pass it to the [process] callback | 331 // Marshal the [message] and pass it to the [process] callback |
| 332 // function. Any promises are converted to a port which expects to | 332 // function. Any promises are converted to a port which expects to |
| 333 // receive a port from the other side down which the remote promise | 333 // receive a port from the other side down which the remote promise |
| (...skipping 36 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 |