Index: packages/quiver/lib/src/async/collect.dart |
diff --git a/packages/quiver/lib/src/async/collect.dart b/packages/quiver/lib/src/async/collect.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6a52a4a4c52d09d22b6d1ad7886b305565a65a05 |
--- /dev/null |
+++ b/packages/quiver/lib/src/async/collect.dart |
@@ -0,0 +1,34 @@ |
+// Copyright 2014 Google Inc. All Rights Reserved. |
+// |
+// Licensed under the Apache License, Version 2.0 (the "License"); |
+// you may not use this file except in compliance with the License. |
+// You may obtain a copy of the License at |
+// |
+// http://www.apache.org/licenses/LICENSE-2.0 |
+// |
+// Unless required by applicable law or agreed to in writing, software |
+// distributed under the License is distributed on an "AS IS" BASIS, |
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+// See the License for the specific language governing permissions and |
+// limitations under the License. |
+ |
+part of quiver.async; |
+ |
+/// Returns a stream of completion events for the input [futures]. |
+/// |
+/// Successfully completed futures yield data events, while futures completed |
+/// with errors yield error events. |
+/// |
+/// The iterator obtained from [futures] is only advanced once the previous |
+/// future completes and yields an event. Thus, lazily creating the futures is |
+/// supported, for example: |
+/// |
+/// collect(files.map((file) => file.readAsString())); |
+/// |
+/// If you need to modify [futures], or a backing collection thereof, before |
+/// the returned stream is done, pass a copy instead to avoid a |
+/// [ConcurrentModificationError]: |
+/// |
+/// collect(files.toList().map((file) => file.readAsString())); |
+Stream collect(Iterable futures) => |
+ new Stream.fromIterable(futures).asyncMap((f) => f); |