Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "dart:collection" show HashMap; | 5 import "dart:collection" show HashMap; |
| 6 | 6 |
| 7 patch class ReceivePort { | 7 patch class ReceivePort { |
| 8 /* patch */ factory ReceivePort() = _ReceivePortImpl; | 8 /* patch */ factory ReceivePort() = _ReceivePortImpl; |
| 9 | 9 |
| 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = | 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 | 50 |
| 51 close() { | 51 close() { |
| 52 _rawPort.close(); | 52 _rawPort.close(); |
| 53 _controller.close(); | 53 _controller.close(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 final RawReceivePort _rawPort; | 56 final RawReceivePort _rawPort; |
| 57 StreamController _controller; | 57 StreamController _controller; |
| 58 } | 58 } |
| 59 | 59 |
| 60 var _pendingImmediateCallback; | |
|
floitsch
2013/11/20 19:37:13
Not yet typed. Will do that.
floitsch
2013/11/21 17:39:47
Done.
| |
| 61 void _isolateScheduleImmediate(void callback()) { | |
| 62 assert(_pendingImmediateCallback == null); | |
| 63 _pendingImmediateCallback = callback; | |
| 64 } | |
| 65 Function _getIsolateScheduleImmediateClosure() { | |
|
floitsch
2013/11/20 19:37:13
ditto.
floitsch
2013/11/21 17:39:47
In the end didn't type it. It's only used for the
| |
| 66 return _isolateScheduleImmediate; | |
| 67 } | |
| 68 | |
| 60 class _RawReceivePortImpl implements RawReceivePort { | 69 class _RawReceivePortImpl implements RawReceivePort { |
| 61 factory _RawReceivePortImpl() native "RawReceivePortImpl_factory"; | 70 factory _RawReceivePortImpl() native "RawReceivePortImpl_factory"; |
| 62 | 71 |
| 63 close() { | 72 close() { |
| 64 _portMap.remove(_id); | 73 _portMap.remove(_id); |
| 65 _closeInternal(_id); | 74 _closeInternal(_id); |
| 66 } | 75 } |
| 67 | 76 |
| 68 SendPort get sendPort { | 77 SendPort get sendPort { |
| 69 return new _SendPortImpl(_id); | 78 return new _SendPortImpl(_id); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 85 | 94 |
| 86 // Called from the VM to retrieve the RawReceivePort for a message. | 95 // Called from the VM to retrieve the RawReceivePort for a message. |
| 87 static _RawReceivePortImpl _lookupReceivePort(int id) { | 96 static _RawReceivePortImpl _lookupReceivePort(int id) { |
| 88 return _portMap[id]; | 97 return _portMap[id]; |
| 89 } | 98 } |
| 90 | 99 |
| 91 // Called from the VM to dispatch to the handler. | 100 // Called from the VM to dispatch to the handler. |
| 92 static void _handleMessage( | 101 static void _handleMessage( |
| 93 _RawReceivePortImpl port, int replyId, var message) { | 102 _RawReceivePortImpl port, int replyId, var message) { |
| 94 assert(port != null); | 103 assert(port != null); |
| 104 // TODO(floitsch): this relies on the fact that any exception aborts the | |
| 105 // VM. Once we have non-fatal global exceptions we need to catch errors | |
| 106 // so that we can run the immediate callbacks. | |
| 95 port._handler(message); | 107 port._handler(message); |
| 108 if (_pendingImmediateCallback != null) { | |
| 109 var callback = _pendingImmediateCallback; | |
| 110 _pendingImmediateCallback = null; | |
| 111 callback(); | |
| 112 } | |
| 96 } | 113 } |
| 97 | 114 |
| 98 // Call into the VM to close the VM maintained mappings. | 115 // Call into the VM to close the VM maintained mappings. |
| 99 static _closeInternal(int id) native "RawReceivePortImpl_closeInternal"; | 116 static _closeInternal(int id) native "RawReceivePortImpl_closeInternal"; |
| 100 | 117 |
| 101 void set handler(Function newHandler) { | 118 void set handler(Function newHandler) { |
| 102 this._handler = newHandler; | 119 this._handler = newHandler; |
| 103 } | 120 } |
| 104 | 121 |
| 105 final int _id; | 122 final int _id; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 } | 259 } |
| 243 | 260 |
| 244 static final RawReceivePort _self = _mainPort; | 261 static final RawReceivePort _self = _mainPort; |
| 245 static RawReceivePort get _mainPort native "Isolate_mainPort"; | 262 static RawReceivePort get _mainPort native "Isolate_mainPort"; |
| 246 | 263 |
| 247 static SendPort _spawnFunction(Function topLevelFunction) | 264 static SendPort _spawnFunction(Function topLevelFunction) |
| 248 native "Isolate_spawnFunction"; | 265 native "Isolate_spawnFunction"; |
| 249 | 266 |
| 250 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; | 267 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; |
| 251 } | 268 } |
| OLD | NEW |