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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } else { | 249 } else { |
250 entryPoint(); | 250 entryPoint(); |
251 } | 251 } |
252 } else { | 252 } else { |
253 entryPoint(message); | 253 entryPoint(message); |
254 } | 254 } |
255 _runPendingImmediateCallback(); | 255 _runPendingImmediateCallback(); |
256 } | 256 } |
257 | 257 |
258 patch class Isolate { | 258 patch class Isolate { |
| 259 static final _currentIsolate = _getCurrentIsolate(); |
| 260 |
| 261 /* patch */ static Isolate get current => _currentIsolate; |
| 262 |
259 /* patch */ static Future<Isolate> spawn( | 263 /* patch */ static Future<Isolate> spawn( |
260 void entryPoint(message), var message, { bool paused: false }) { | 264 void entryPoint(message), var message, { bool paused: false }) { |
261 // `paused` isn't handled yet. | 265 // `paused` isn't handled yet. |
262 RawReceivePort readyPort; | 266 RawReceivePort readyPort; |
263 try { | 267 try { |
264 // The VM will invoke [_startIsolate] with entryPoint as argument. | 268 // The VM will invoke [_startIsolate] with entryPoint as argument. |
265 readyPort = new RawReceivePort(); | 269 readyPort = new RawReceivePort(); |
266 _spawnFunction(readyPort.sendPort, entryPoint, message); | 270 _spawnFunction(readyPort.sendPort, entryPoint, message); |
267 Completer completer = new Completer<Isolate>.sync(); | 271 Completer completer = new Completer<Isolate>.sync(); |
268 readyPort.handler = (readyMessage) { | 272 readyPort.handler = (readyMessage) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 throw new UnsupportedError("ping"); | 376 throw new UnsupportedError("ping"); |
373 } | 377 } |
374 | 378 |
375 /* patch */ void addErrorListener(SendPort port) { | 379 /* patch */ void addErrorListener(SendPort port) { |
376 throw new UnsupportedError("addErrorListener"); | 380 throw new UnsupportedError("addErrorListener"); |
377 } | 381 } |
378 | 382 |
379 /* patch */ void removeErrorListener(SendPort port) { | 383 /* patch */ void removeErrorListener(SendPort port) { |
380 throw new UnsupportedError("removeErrorListener"); | 384 throw new UnsupportedError("removeErrorListener"); |
381 } | 385 } |
| 386 |
| 387 static Isolate _getCurrentIsolate() { |
| 388 List portAndCapabilities = _getPortAndCapabilitiesOfCurrentIsolate(); |
| 389 return new Isolate(portAndCapabilities[0], |
| 390 pauseCapability: portAndCapabilities[1], |
| 391 terminateCapability: portAndCapabilities[2]); |
| 392 } |
| 393 |
| 394 static List _getPortAndCapabilitiesOfCurrentIsolate() |
| 395 native "Isolate_getPortAndCapabilitiesOfCurrentIsolate"; |
382 } | 396 } |
OLD | NEW |