OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library barback.utils; | 5 library barback.utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 /// A pair of values. | 9 /// A pair of values. |
10 class Pair<E, F> { | 10 class Pair<E, F> { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 streams = streams.toList(); | 130 streams = streams.toList(); |
131 var doneCount = 0; | 131 var doneCount = 0; |
132 // Use a sync stream to preserve the synchrony behavior of the input streams. | 132 // Use a sync stream to preserve the synchrony behavior of the input streams. |
133 // If the inputs are sync, then this will be sync as well; if the inputs are | 133 // If the inputs are sync, then this will be sync as well; if the inputs are |
134 // async, then the events we receive will also be async, and forwarding them | 134 // async, then the events we receive will also be async, and forwarding them |
135 // sync won't change that. | 135 // sync won't change that. |
136 var controller = broadcast ? new StreamController.broadcast(sync: true) | 136 var controller = broadcast ? new StreamController.broadcast(sync: true) |
137 : new StreamController(sync: true); | 137 : new StreamController(sync: true); |
138 | 138 |
139 for (var stream in streams) { | 139 for (var stream in streams) { |
140 stream.listen((value) { | 140 stream.listen( |
141 controller.add(value); | 141 controller.add, |
142 }, onError: (error) { | 142 onError: controller.addError, |
143 controller.addError(error); | 143 onDone: () { |
144 }, onDone: () { | 144 doneCount++; |
145 doneCount++; | 145 if (doneCount == streams.length) controller.close(); |
146 if (doneCount == streams.length) controller.close(); | 146 }); |
nweiz
2013/10/07 18:49:51
The indentation here is wrong. It should be:
stre
floitsch
2013/10/10 14:22:52
Done.
| |
147 }); | |
148 } | 147 } |
149 | 148 |
150 return controller.stream; | 149 return controller.stream; |
151 } | 150 } |
152 | 151 |
153 /// Prepends each line in [text] with [prefix]. If [firstPrefix] is passed, the | 152 /// Prepends each line in [text] with [prefix]. If [firstPrefix] is passed, the |
154 /// first line is prefixed with that instead. | 153 /// first line is prefixed with that instead. |
155 String prefixLines(String text, {String prefix: '| ', String firstPrefix}) { | 154 String prefixLines(String text, {String prefix: '| ', String firstPrefix}) { |
156 var lines = text.split('\n'); | 155 var lines = text.split('\n'); |
157 if (firstPrefix == null) { | 156 if (firstPrefix == null) { |
(...skipping 23 matching lines...) Expand all Loading... | |
181 Future newFuture(callback()) => new Future.value().then((_) => callback()); | 180 Future newFuture(callback()) => new Future.value().then((_) => callback()); |
182 | 181 |
183 /// Returns a buffered stream that will emit the same values as the stream | 182 /// Returns a buffered stream that will emit the same values as the stream |
184 /// returned by [future] once [future] completes. If [future] completes to an | 183 /// returned by [future] once [future] completes. If [future] completes to an |
185 /// error, the return value will emit that error and then close. | 184 /// error, the return value will emit that error and then close. |
186 Stream futureStream(Future<Stream> future) { | 185 Stream futureStream(Future<Stream> future) { |
187 var controller = new StreamController(sync: true); | 186 var controller = new StreamController(sync: true); |
188 future.then((stream) { | 187 future.then((stream) { |
189 stream.listen( | 188 stream.listen( |
190 controller.add, | 189 controller.add, |
191 onError: (error) => controller.addError(error), | 190 onError: controller.addError, |
192 onDone: controller.close); | 191 onDone: controller.close); |
193 }).catchError((e) { | 192 }).catchError((e, StackTrace stackTrace) { |
nweiz
2013/10/07 18:49:51
Should this stackTrace parameter be optional? It's
floitsch
2013/10/10 14:22:52
We know where the catchError comes from. (It's fro
| |
194 controller.addError(e); | 193 controller.addError(e, stackTrace); |
195 controller.close(); | 194 controller.close(); |
196 }); | 195 }); |
197 return controller.stream; | 196 return controller.stream; |
198 } | 197 } |
OLD | NEW |