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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 /// The return values of all [Future]s are discarded. Any errors will cause the | 243 /// The return values of all [Future]s are discarded. Any errors will cause the |
244 /// iteration to stop and will be piped through the return value. | 244 /// iteration to stop and will be piped through the return value. |
245 Future forEachFuture(Iterable input, Future fn(element)) { | 245 Future forEachFuture(Iterable input, Future fn(element)) { |
246 var iterator = input.iterator; | 246 var iterator = input.iterator; |
247 Future nextElement(_) { | 247 Future nextElement(_) { |
248 if (!iterator.moveNext()) return new Future.immediate(null); | 248 if (!iterator.moveNext()) return new Future.immediate(null); |
249 return fn(iterator.current).then(nextElement); | 249 return fn(iterator.current).then(nextElement); |
250 } | 250 } |
251 return nextElement(null); | 251 return nextElement(null); |
252 } | 252 } |
253 | |
254 // TODO(nweiz): remove this when issue 8310 is fixed. | |
255 /// Returns a [Stream] identical to [stream], but piped through a new | |
256 /// [StreamController]. This exists to work around issue 8310. | |
257 Stream wrapStream(Stream stream) { | |
258 var controller = stream.isBroadcast | |
259 ? new StreamController.broadcast() | |
260 : new StreamController(); | |
261 stream.listen(controller.add, | |
262 onError: (e) => controller.signalError(e), | |
263 onDone: controller.close); | |
264 return controller.stream; | |
265 } | |
OLD | NEW |