OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 utils; | 5 library utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:crypto'; | 8 import 'dart:crypto'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:scalarlist'; | 10 import 'dart:scalarlist'; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 /// The return values of all [Future]s are discarded. Any errors will cause the | 302 /// The return values of all [Future]s are discarded. Any errors will cause the |
303 /// iteration to stop and will be piped through the return value. | 303 /// iteration to stop and will be piped through the return value. |
304 Future forEachFuture(Iterable input, Future fn(element)) { | 304 Future forEachFuture(Iterable input, Future fn(element)) { |
305 var iterator = input.iterator; | 305 var iterator = input.iterator; |
306 Future nextElement(_) { | 306 Future nextElement(_) { |
307 if (!iterator.moveNext()) return new Future.immediate(null); | 307 if (!iterator.moveNext()) return new Future.immediate(null); |
308 return fn(iterator.current).then(nextElement); | 308 return fn(iterator.current).then(nextElement); |
309 } | 309 } |
310 return nextElement(null); | 310 return nextElement(null); |
311 } | 311 } |
| 312 |
| 313 // TODO(nweiz): remove this when issue 8310 is fixed. |
| 314 /// Returns a [Stream] identical to [stream], but piped through a new |
| 315 /// [StreamController]. This exists to work around issue 8310. |
| 316 Stream wrapStream(Stream stream) { |
| 317 var controller = stream.isBroadcast |
| 318 ? new StreamController.broadcast() |
| 319 : new StreamController(); |
| 320 stream.listen(controller.add, |
| 321 onError: (e) => controller.signalError(e), |
| 322 onDone: controller.close); |
| 323 return controller.stream; |
| 324 } |
OLD | NEW |