| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | 6 |
| 7 /// A collection of streams whose events are unified and sent through a central | 7 /// A collection of streams whose events are unified and sent through a central |
| 8 /// stream. | 8 /// stream. |
| 9 /// | 9 /// |
| 10 /// Both errors and data events are forwarded through [stream]. The streams in | 10 /// Both errors and data events are forwarded through [stream]. The streams in |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 /// If it's a broadcast group and it goes dormant again, broadcast stream | 46 /// If it's a broadcast group and it goes dormant again, broadcast stream |
| 47 /// subscriptions will be canceled and set to null again. Single-subscriber | 47 /// subscriptions will be canceled and set to null again. Single-subscriber |
| 48 /// stream subscriptions will be left intact, since they can't be | 48 /// stream subscriptions will be left intact, since they can't be |
| 49 /// re-subscribed. | 49 /// re-subscribed. |
| 50 final _subscriptions = new Map<Stream<T>, StreamSubscription<T>>(); | 50 final _subscriptions = new Map<Stream<T>, StreamSubscription<T>>(); |
| 51 | 51 |
| 52 /// Merges the events from [streams] into a single (single-subscriber) stream. | 52 /// Merges the events from [streams] into a single (single-subscriber) stream. |
| 53 /// | 53 /// |
| 54 /// This is equivalent to adding [streams] to a group, closing that group, and | 54 /// This is equivalent to adding [streams] to a group, closing that group, and |
| 55 /// returning its stream. | 55 /// returning its stream. |
| 56 static Stream/*<T>*/ merge/*<T>*/(Iterable<Stream/*<T>*/> streams) { | 56 static Stream<T> merge<T>(Iterable<Stream<T>> streams) { |
| 57 var group = new StreamGroup/*<T>*/(); | 57 var group = new StreamGroup<T>(); |
| 58 streams.forEach(group.add); | 58 streams.forEach(group.add); |
| 59 group.close(); | 59 group.close(); |
| 60 return group.stream; | 60 return group.stream; |
| 61 } | 61 } |
| 62 | 62 |
| 63 /// Creates a new stream group where [stream] is single-subscriber. | 63 /// Creates a new stream group where [stream] is single-subscriber. |
| 64 StreamGroup() { | 64 StreamGroup() { |
| 65 _controller = new StreamController<T>( | 65 _controller = new StreamController<T>( |
| 66 onListen: _onListen, | 66 onListen: _onListen, |
| 67 onPause: _onPause, | 67 onPause: _onPause, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 /// The name of the state. | 249 /// The name of the state. |
| 250 /// | 250 /// |
| 251 /// Used for debugging. | 251 /// Used for debugging. |
| 252 final String name; | 252 final String name; |
| 253 | 253 |
| 254 const _StreamGroupState(this.name); | 254 const _StreamGroupState(this.name); |
| 255 | 255 |
| 256 String toString() => name; | 256 String toString() => name; |
| 257 } | 257 } |
| OLD | NEW |