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

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

Issue 11881030: No longer work around issue 7761. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « no previous file | utils/pub/io.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/lib/src/utils.dart
diff --git a/pkg/http/lib/src/utils.dart b/pkg/http/lib/src/utils.dart
index 28e2bfbec3141a0f8a7e42fef898ff92b49d8738..bca314d95cf1828fe0f51b6b7b612b8d379d469c 100644
--- a/pkg/http/lib/src/utils.dart
+++ b/pkg/http/lib/src/utils.dart
@@ -172,8 +172,7 @@ StreamConsumer<List<int>, dynamic> wrapOutputStream(OutputStream stream) =>
class _OutputStreamConsumer implements StreamConsumer<List<int>, dynamic> {
final OutputStream _outputStream;
- _OutputStreamConsumer(this._outputStream)
- : super();
+ _OutputStreamConsumer(this._outputStream);
Future consume(Stream<List<int>> stream) {
// TODO(nweiz): we have to manually keep track of whether or not the
@@ -182,19 +181,29 @@ class _OutputStreamConsumer implements StreamConsumer<List<int>, dynamic> {
// the following TODO.
var completed = false;
var completer = new Completer();
- stream.listen((data) => _outputStream.write(data), onDone: () {
- _outputStream.close();
- // TODO(nweiz): wait until _outputStream.onClosed is called once issue
- // 7761 is fixed.
- if (!completed) completer.complete();
- completed = true;
- });
+ stream.listen((data) {
+ // Writing empty data to a closed stream can cause errors.
+ if (data.isEmpty) return;
+
+ // TODO(nweiz): remove this try/catch when issue 7836 is fixed.
+ try {
+ _outputStream.write(data);
+ } catch (e, stack) {
+ if (!completed) completer.completeError(e, stack);
+ completed = true;
+ }
+ }, onDone: () => _outputStream.close());
_outputStream.onError = (e) {
if (!completed) completer.completeError(e);
completed = true;
};
+ _outputStream.onClosed = () {
+ if (!completed) completer.complete();
+ completed = true;
+ };
+
return completer.future;
}
}
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698