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

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

Issue 185543004: Merge all http-outgoing transfomers into _HttpOutgoing, including simpler(better) buffering. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup Created 6 years, 10 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') | tests/standalone/io/http_10_test.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 e2ea2bd63abb9bc065d8108862febc832f6c074a..74d12b475c032497e22378729bb08c3def0919a5 100644
--- a/sdk/lib/io/io_sink.dart
+++ b/sdk/lib/io/io_sink.dart
@@ -110,10 +110,18 @@ class _StreamSinkImpl<T> implements StreamSink<T> {
}
Future flush() {
+ if (_isBound) {
+ throw new StateError("StreamSink is bound to a stream");
+ }
+ if (_controllerInstance == null) return new Future.value(this);
// 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);
+ _isBound = true;
+ var future = _controllerCompleter.future;
+ _controllerInstance.close();
+ return future.whenComplete(() {
+ _isBound = false;
+ });
}
Future close() {
@@ -165,7 +173,7 @@ class _StreamSinkImpl<T> implements StreamSink<T> {
(_) {
if (_isBound) {
// A new stream takes over - forward values to that stream.
- _controllerCompleter.complete();
+ _controllerCompleter.complete(this);
_controllerCompleter = null;
_controllerInstance = null;
} else {
@@ -221,7 +229,7 @@ class _IOSinkImpl extends _StreamSinkImpl<List<int>> implements IOSink {
}
}
if (string.isEmpty) return;
- add(_encoding.encode(string));
+ add(encoding.encode(string));
}
void writeAll(Iterable objects, [String separator = ""]) {
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | tests/standalone/io/http_10_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698