Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Unified Diff: pkg/barback/lib/src/utils.dart

Issue 23543005: Make Transform a little more pleasant to use: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/barback/lib/src/transform.dart ('k') | pkg/barback/test/package_graph/transform_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/utils.dart
diff --git a/pkg/barback/lib/src/utils.dart b/pkg/barback/lib/src/utils.dart
index 0a41c8ed08a5935f0dd67ee31e1c19ce948e2c1a..37816bcfe8120bee4732c7b8070f303ccc8dff87 100644
--- a/pkg/barback/lib/src/utils.dart
+++ b/pkg/barback/lib/src/utils.dart
@@ -179,3 +179,20 @@ Future pumpEventQueue([int times=20]) {
/// Like [new Future], but avoids issue 11911 by using [new Future.value] under
/// the covers.
Future newFuture(callback()) => new Future.value().then((_) => callback());
+
+/// Returns a buffered stream that will emit the same values as the stream
+/// returned by [future] once [future] completes. If [future] completes to an
+/// error, the return value will emit that error and then close.
+Stream futureStream(Future<Stream> future) {
+ var controller = new StreamController(sync: true);
+ future.then((stream) {
+ stream.listen(
+ controller.add,
+ onError: (error) => controller.addError(error),
+ onDone: controller.close);
+ }).catchError((e) {
+ controller.addError(e);
+ controller.close();
+ });
+ return controller.stream;
+}
« no previous file with comments | « pkg/barback/lib/src/transform.dart ('k') | pkg/barback/test/package_graph/transform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698