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

Unified Diff: tests/isolate/mandel_isolate_test.dart

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 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 | « tests/isolate/mandel_isolate_stream_test.dart ('k') | tests/isolate/message2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/isolate/mandel_isolate_test.dart
diff --git a/tests/isolate/mandel_isolate_test.dart b/tests/isolate/mandel_isolate_test.dart
index 9e3e14feab8fadb23287d57860831cbfe53db1cb..241ff29065745d6fe6f27d3e50097332724c092c 100644
--- a/tests/isolate/mandel_isolate_test.dart
+++ b/tests/isolate/mandel_isolate_test.dart
@@ -37,8 +37,10 @@ class MandelbrotState {
void startClient(int id) {
assert(_sent < N);
- final client = new LineProcessorClient(this, id);
- client.processLine(_sent++);
+ int line = _sent++;
+ LineProcessorClient.create(this, id).then((final client) {
+ client.processLine(line);
+ });
}
void notifyProcessedLine(LineProcessorClient client, int y, List<int> line) {
@@ -86,24 +88,32 @@ class MandelbrotState {
class LineProcessorClient {
+ MandelbrotState _state;
+ int _id;
+ SendPort _port;
+
+ LineProcessorClient(this._state, this._id, this._port);
- LineProcessorClient(MandelbrotState this._state, int this._id) {
- _port = spawnFunction(processLines);
+ static Future<LineProcessorClient> create(MandelbrotState state, int id) {
+ ReceivePort reply = new ReceivePort();
+ return Isolate.spawn(processLines, reply.sendPort).then((_) {
+ return reply.first.then((port) {
+ return new LineProcessorClient(state, id, port);
+ });
+ });
}
void processLine(int y) {
- _port.call(y).then((List<int> message) {
+ ReceivePort reply = new ReceivePort();
+ _port.send([y, reply.sendPort]);
+ reply.first.then((List<int> message) {
_state.notifyProcessedLine(this, y, message);
});
}
void shutdown() {
- _port.send(TERMINATION_MESSAGE, null);
+ _port.send(TERMINATION_MESSAGE);
}
-
- MandelbrotState _state;
- int _id;
- SendPort _port;
}
List<int> processLine(int y) {
@@ -133,13 +143,16 @@ List<int> processLine(int y) {
return result;
}
-void processLines() {
- port.receive((message, SendPort replyTo) {
- if (message == TERMINATION_MESSAGE) {
- assert(replyTo == null);
- port.close();
+void processLines(SendPort replyPort) {
+ ReceivePort port = new ReceivePort();
+ port.listen((message) {
+ if (message != TERMINATION_MESSAGE) {
+ int line = message[0];
+ SendPort replyTo = message[1];
+ replyTo.send(processLine(line));
} else {
- replyTo.send(processLine(message), null);
+ port.close();
}
});
+ replyPort.send(port.sendPort);
}
« no previous file with comments | « tests/isolate/mandel_isolate_stream_test.dart ('k') | tests/isolate/message2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698