| OLD | NEW |
| 1 // Copyright 2014 Google Inc. All Rights Reserved. | 1 // Copyright 2014 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 part of quiver.streams; | 15 part of quiver.async; |
| 16 | 16 |
| 17 /** | 17 /// Returns the concatentation of the input streams. |
| 18 * Returns the concatentation of the input streams. | 18 /// |
| 19 * | 19 /// When the returned stream is listened to, the [streams] are iterated through |
| 20 * When the returned stream is listened to, the [streams] are iterated through | 20 /// asynchronously, forwarding all events (both data and error) for the current |
| 21 * asynchronously, forwarding all events (both data and error) for the current | 21 /// stream to the returned stream before advancing the iterator and listening |
| 22 * stream to the returned stream before advancing the iterator and listening to | 22 /// to the next stream. If advancing the iterator throws an error, the |
| 23 * the next stream. If advancing the iterator throws an error, the returned | 23 /// returned stream ends immediately with that error. |
| 24 * stream ends immediately with that error. | 24 /// |
| 25 * | 25 /// Pausing and resuming the returned stream's subscriptions will pause and |
| 26 * Pausing and resuming the returned stream's subscriptions will pause and | 26 /// resume the subscription of the current stream being listened to. |
| 27 * resume the subscription of the current stream being listened to. | 27 /// |
| 28 * | 28 /// Note: Events from pre-existing broadcast streams which occur before the |
| 29 * Note: Events from pre-existing broadcast streams which occur before | 29 /// stream is reached by the iteration will be dropped. |
| 30 * the stream is reached by the iteration will be dropped. | 30 /// |
| 31 * | 31 /// Example: |
| 32 * Example: | 32 /// |
| 33 * | 33 /// concat(files.map((file) => |
| 34 * concat(files.map((file) => | 34 /// file.openRead().transform(const LineSplitter()))) |
| 35 * file.openRead().transform(const LineSplitter()))) | |
| 36 * | |
| 37 */ | |
| 38 Stream concat(Iterable<Stream> streams) => new _ConcatStream(streams); | 35 Stream concat(Iterable<Stream> streams) => new _ConcatStream(streams); |
| 39 | 36 |
| 40 class _ConcatStream extends Stream { | 37 class _ConcatStream extends Stream { |
| 41 final Iterable<Stream> _streams; | 38 final Iterable<Stream> _streams; |
| 42 | 39 |
| 43 _ConcatStream(Iterable<Stream> streams) : _streams = streams; | 40 _ConcatStream(Iterable<Stream> streams) : _streams = streams; |
| 44 | 41 |
| 45 StreamSubscription listen(void onData(var data), | 42 StreamSubscription listen(void onData(var data), |
| 46 {Function onError, void onDone(), bool cancelOnError}) { | 43 {Function onError, void onDone(), bool cancelOnError}) { |
| 47 cancelOnError = true == cancelOnError; | 44 cancelOnError = true == cancelOnError; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 76 }, onCancel: () { | 73 }, onCancel: () { |
| 77 if (currentSubscription != null) return currentSubscription.cancel(); | 74 if (currentSubscription != null) return currentSubscription.cancel(); |
| 78 }); | 75 }); |
| 79 | 76 |
| 80 nextStream(); | 77 nextStream(); |
| 81 | 78 |
| 82 return controller.stream.listen(onData, | 79 return controller.stream.listen(onData, |
| 83 onError: onError, onDone: onDone, cancelOnError: cancelOnError); | 80 onError: onError, onDone: onDone, cancelOnError: cancelOnError); |
| 84 } | 81 } |
| 85 } | 82 } |
| OLD | NEW |