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

Unified Diff: sdk/lib/io/io_sink.dart

Issue 52263005: Add IOSink:flush(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | « sdk/lib/io/http_impl.dart ('k') | sdk/lib/io/stdio.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/io_sink.dart
diff --git a/sdk/lib/io/io_sink.dart b/sdk/lib/io/io_sink.dart
index 042a469fb67c770216b9d1c07def35d8e9e2e02d..45390d88375c6552ce068286a2ea0e0d5bd8e2c6 100644
--- a/sdk/lib/io/io_sink.dart
+++ b/sdk/lib/io/io_sink.dart
@@ -46,6 +46,17 @@ abstract class IOSink implements StreamSink<List<int>>, StringSink {
Future addStream(Stream<List<int>> stream);
/**
+ * Returns a [Future] that completes once all buffered data is accepted by the
+ * to underlying [StreamConsumer].
+ *
+ * It's an error to call this method, while an [addStream] is incomplete.
+ *
+ * NOTE: This is not necessarily the same as the data being flushed by the
+ * operating system.
+ */
+ Future flush();
+
+ /**
* Close the target.
*/
Future close();
@@ -99,6 +110,13 @@ class _StreamSinkImpl<T> implements StreamSink<T> {
return future.then((_) => targetAddStream());
}
+ Future flush() {
+ // Adding an empty stream-controller will return a future that will complete
+ // when all data is done.
+ var controller = new StreamController()..close();
+ return addStream(controller.stream).then((_) => this);
+ }
+
Future close() {
if (_isBound) {
throw new StateError("StreamSink is bound to a stream");
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | sdk/lib/io/stdio.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698