| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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:async'; | 5 import 'dart:async'; |
| 6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 | 7 |
| 8 import '../stream_channel.dart'; | 8 import '../stream_channel.dart'; |
| 9 | 9 |
| 10 /// A [StreamChannel] that communicates over a [ReceivePort]/[SendPort] pair, | 10 /// A [StreamChannel] that communicates over a [ReceivePort]/[SendPort] pair, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 121 } |
| 122 | 122 |
| 123 return done; | 123 return done; |
| 124 } | 124 } |
| 125 | 125 |
| 126 Future addStream(Stream<T> stream) { | 126 Future addStream(Stream<T> stream) { |
| 127 if (_closed) throw new StateError("Cannot add stream after closing."); | 127 if (_closed) throw new StateError("Cannot add stream after closing."); |
| 128 if (_inAddStream) { | 128 if (_inAddStream) { |
| 129 throw new StateError("Cannot add stream while adding stream."); | 129 throw new StateError("Cannot add stream while adding stream."); |
| 130 } | 130 } |
| 131 if (_isDone) return; | 131 if (_isDone) return new Future.value(); |
| 132 | 132 |
| 133 _inAddStream = true; | 133 _inAddStream = true; |
| 134 var completer = new Completer.sync(); | 134 var completer = new Completer.sync(); |
| 135 stream.listen(_add, | 135 stream.listen(_add, |
| 136 onError: (error, stackTrace) { | 136 onError: (error, stackTrace) { |
| 137 _close(error, stackTrace); | 137 _close(error, stackTrace); |
| 138 completer.complete(); | 138 completer.complete(); |
| 139 }, | 139 }, |
| 140 onDone: completer.complete, | 140 onDone: completer.complete, |
| 141 cancelOnError: true); | 141 cancelOnError: true); |
| 142 return completer.future.then((_) { | 142 return completer.future.then((_) { |
| 143 _inAddStream = false; | 143 _inAddStream = false; |
| 144 }); | 144 }); |
| 145 } | 145 } |
| 146 } | 146 } |
| OLD | NEW |