Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Unified Diff: runtime/lib/isolate_patch.dart

Issue 507913003: Create isolates in a separate thread. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/isolate_patch.dart
diff --git a/runtime/lib/isolate_patch.dart b/runtime/lib/isolate_patch.dart
index 39826f656a469ed179aab3353180142ac6db3dd9..ff4f0c67c38babe4d650f8904ad8d153a278125f 100644
--- a/runtime/lib/isolate_patch.dart
+++ b/runtime/lib/isolate_patch.dart
@@ -253,18 +253,7 @@ patch class Isolate {
// The VM will invoke [_startIsolate] with entryPoint as argument.
readyPort = new RawReceivePort();
_spawnFunction(readyPort.sendPort, entryPoint, message);
- Completer completer = new Completer<Isolate>.sync();
- readyPort.handler = (readyMessage) {
- readyPort.close();
- assert(readyMessage is List);
- assert(readyMessage.length == 2);
- SendPort controlPort = readyMessage[0];
- List capabilities = readyMessage[1];
- completer.complete(new Isolate(controlPort,
- pauseCapability: capabilities[0],
- terminateCapability: capabilities[1]));
- };
- return completer.future;
+ return spawnCommon(readyPort);
} catch (e, st) {
if (readyPort != null) {
readyPort.close();
@@ -281,23 +270,34 @@ patch class Isolate {
// The VM will invoke [_startIsolate] and not `main`.
readyPort = new RawReceivePort();
_spawnUri(readyPort.sendPort, uri.toString(), args, message);
- Completer completer = new Completer<Isolate>.sync();
- readyPort.handler = (readyMessage) {
+ return spawnCommon(readyPort);
+ } catch (e, st) {
+ if (readyPort != null) {
readyPort.close();
- assert(readyMessage is List);
- assert(readyMessage.length == 2);
+ }
+ return new Future<Isolate>.error(e, st);
+ };
+ }
+
+ static Future<Isolate> spawnCommon(RawReceivePort readyPort) {
+ Completer completer = new Completer<Isolate>.sync();
+ readyPort.handler = (readyMessage) {
+ readyPort.close();
+ if (readyMessage is String) {
+ // We encountered an error starting the new isolate.
+ completer.completeError(new IsolateSpawnException(
+ "Unable to spawn child isolate:\n${readyMessage}"));
+ } else if (readyMessage is List &&
+ readyMessage.length == 2) {
SendPort controlPort = readyMessage[0];
List capabilities = readyMessage[1];
completer.complete(new Isolate(controlPort,
pauseCapability: capabilities[0],
terminateCapability: capabilities[1]));
- };
- return completer.future;
- } catch (e, st) {
- if (readyPort != null) {
- readyPort.close();
+ } else {
+ completer.completeError(new IsolateSpawnException(
+ "Internal error: received unexpected message $readyMessage"));
}
- return new Future<Isolate>.error(e, st);
};
return completer.future;
}
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698