| Index: tests/isolate/mandel_isolate_stream_test.dart
|
| diff --git a/tests/isolate/mandel_isolate_test.dart b/tests/isolate/mandel_isolate_stream_test.dart
|
| similarity index 83%
|
| copy from tests/isolate/mandel_isolate_test.dart
|
| copy to tests/isolate/mandel_isolate_stream_test.dart
|
| index 3e0354475fe5385c5cf0454cb5be1a830343a0f4..302696e58b5326967003f96fde43cb34731d3d54 100644
|
| --- a/tests/isolate/mandel_isolate_test.dart
|
| +++ b/tests/isolate/mandel_isolate_stream_test.dart
|
| @@ -86,22 +86,29 @@ class MandelbrotState {
|
| class LineProcessorClient {
|
|
|
| LineProcessorClient(MandelbrotState this._state, int this._id) {
|
| - _port = spawnFunction(processLines);
|
| + _sink = streamSpawnFunction(processLines);
|
| + _box = new MessageBox();
|
| + _sink.add(_box.sink);
|
| + _box.stream.listen((List<int> message) {
|
| + _state.notifyProcessedLine(this, _currentLine, message);
|
| + });
|
| }
|
|
|
| void processLine(int y) {
|
| - _port.call(y).then((List<int> message) {
|
| - _state.notifyProcessedLine(this, y, message);
|
| - });
|
| + _currentLine = y;
|
| + _sink.add(y);
|
| }
|
|
|
| void shutdown() {
|
| - _port.send(TERMINATION_MESSAGE, null);
|
| + _sink.close();
|
| + _box.stream.close();
|
| }
|
|
|
| MandelbrotState _state;
|
| int _id;
|
| - SendPort _port;
|
| + IsolateSink _sink;
|
| + int _currentLine;
|
| + MessageBox _box;
|
| }
|
|
|
| List<int> processLine(int y) {
|
| @@ -132,12 +139,15 @@ List<int> processLine(int y) {
|
| }
|
|
|
| void processLines() {
|
| - port.receive((message, SendPort replyTo) {
|
| - if (message == TERMINATION_MESSAGE) {
|
| - assert(replyTo == null);
|
| - port.close();
|
| - } else {
|
| - replyTo.send(processLine(message), null);
|
| + bool isFirst = true;
|
| + IsolateSink replyTo;
|
| +
|
| + stream.listen((message) {
|
| + if (isFirst) {
|
| + isFirst = false;
|
| + replyTo = message;
|
| + return;
|
| }
|
| + replyTo.add(processLine(message));
|
| });
|
| }
|
|
|