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 patch class ReceivePort { | 5 patch class ReceivePort { |
6 /* patch */ factory ReceivePort() { | 6 /* patch */ factory ReceivePort() { |
7 return new _ReceivePortImpl(); | 7 return new _ReceivePortImpl(); |
8 } | 8 } |
9 } | 9 } |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 _sendInternal(_id, replyId, message); | 78 _sendInternal(_id, replyId, message); |
79 } | 79 } |
80 | 80 |
81 Future call(var message) { | 81 Future call(var message) { |
82 final completer = new Completer(); | 82 final completer = new Completer(); |
83 final port = new _ReceivePortImpl(); | 83 final port = new _ReceivePortImpl(); |
84 send(message, port.toSendPort()); | 84 send(message, port.toSendPort()); |
85 port.receive((value, ignoreReplyTo) { | 85 port.receive((value, ignoreReplyTo) { |
86 port.close(); | 86 port.close(); |
87 if (value is Exception) { | 87 if (value is Exception) { |
88 completer.completeException(value); | 88 completer.completeError(value); |
89 } else { | 89 } else { |
90 completer.complete(value); | 90 completer.complete(value); |
91 } | 91 } |
92 }); | 92 }); |
93 return completer.future; | 93 return completer.future; |
94 } | 94 } |
95 | 95 |
96 bool operator==(var other) { | 96 bool operator==(var other) { |
97 return (other is _SendPortImpl) && _id == other._id; | 97 return (other is _SendPortImpl) && _id == other._id; |
98 } | 98 } |
(...skipping 16 matching lines...) Expand all Loading... |
115 static _sendInternal(int sendId, int replyId, var message) | 115 static _sendInternal(int sendId, int replyId, var message) |
116 native "SendPortImpl_sendInternal_"; | 116 native "SendPortImpl_sendInternal_"; |
117 | 117 |
118 final int _id; | 118 final int _id; |
119 } | 119 } |
120 | 120 |
121 _getPortInternal() native "isolate_getPortInternal"; | 121 _getPortInternal() native "isolate_getPortInternal"; |
122 | 122 |
123 ReceivePort _portInternal; | 123 ReceivePort _portInternal; |
124 | 124 |
125 patch ReceivePort get port { | 125 patch class _Isolate { |
126 if (_portInternal == null) { | 126 /* patch */ static ReceivePort get port { |
127 _portInternal = _getPortInternal(); | 127 if (_portInternal == null) { |
128 } | 128 _portInternal = _getPortInternal(); |
129 return _portInternal; | |
130 } | |
131 | |
132 patch spawnFunction(void topLevelFunction(), | |
133 [bool UnhandledExceptionCallback(IsolateUnhandledException e)]) | |
134 native "isolate_spawnFunction"; | |
135 | |
136 patch spawnUri(String uri) native "isolate_spawnUri"; | |
137 | |
138 patch class Timer { | |
139 /* patch */ factory Timer(int milliseconds, void callback(Timer timer)) { | |
140 if (_TimerFactory._factory == null) { | |
141 throw new UnsupportedError("Timer interface not supported."); | |
142 } | 129 } |
143 return _TimerFactory._factory(milliseconds, callback, false); | 130 return _portInternal; |
144 } | 131 } |
145 | 132 |
146 /** | 133 /* patch */ static spawnFunction(void topLevelFunction(), |
147 * Creates a new repeating timer. The [callback] is invoked every | 134 [bool UnhandledExceptionCallback(IsolateUnhandledException e)]) |
148 * [milliseconds] millisecond until cancelled. | 135 native "isolate_spawnFunction"; |
149 */ | 136 |
150 /* patch */ factory Timer.repeating(int milliseconds, | 137 /* patch */ static spawnUri(String uri) native "isolate_spawnUri"; |
151 void callback(Timer timer)) { | |
152 if (_TimerFactory._factory == null) { | |
153 throw new UnsupportedError("Timer interface not supported."); | |
154 } | |
155 return _TimerFactory._factory(milliseconds, callback, true); | |
156 } | |
157 } | 138 } |
158 | |
159 typedef Timer _TimerFactoryClosure(int milliseconds, | |
160 void callback(Timer timer), | |
161 bool repeating); | |
162 | |
163 class _TimerFactory { | |
164 static _TimerFactoryClosure _factory; | |
165 } | |
166 | |
167 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets | |
168 // [_TimerFactory._factory] directly. | |
169 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { | |
170 _TimerFactory._factory = closure; | |
171 } | |
OLD | NEW |