Chromium Code Reviews| 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..381d0d629d5c533487f5ac871f2a927ef83d645a 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,30 @@ 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(MandebrotState state, int id) { |
| + ReceivePort reply = new ReceivePort(); |
| + Future isolateStart = Isolate.spawn(processLines, reply.sendPort); |
|
floitsch
2013/10/23 13:33:24
No need for temporary variable.
Isolate.spawn(pro
Lasse Reichstein Nielsen
2013/10/24 10:26:01
I just thought the line-breaks looked better this
|
| + return isolateStart.then((_) => |
| + reply.first.then((port) => new LineProcessorClient(state, id, port))); |
| } |
| void processLine(int y) { |
| - _port.call(y).then((List<int> message) { |
| + ReceivePort reply = new ReceivePort(); |
| + reply.first.then((List<int> message) { |
| _state.notifyProcessedLine(this, y, message); |
| }); |
| + _port.send([y, reply.sendPort]); |
|
floitsch
2013/10/23 13:33:24
I prefer the "right" order.
ReceivePort reply = .
Lasse Reichstein Nielsen
2013/10/24 10:26:01
I actually consider that the wrong order.
The safe
|
| } |
| void shutdown() { |
| - _port.send(TERMINATION_MESSAGE, null); |
| + _port.send(TERMINATION_MESSAGE); |
| } |
| - |
| - MandelbrotState _state; |
| - int _id; |
| - SendPort _port; |
| } |
| List<int> processLine(int y) { |
| @@ -133,13 +141,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); |
| } |