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

Side by Side Diff: sdk/lib/io/http_impl.dart

Issue 14753009: Make StreamSubscription be the active part of a stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpIncoming extends Stream<List<int>> { 7 class _HttpIncoming extends Stream<List<int>> {
8 final int _transferLength; 8 final int _transferLength;
9 final Completer _dataCompleter = new Completer(); 9 final Completer _dataCompleter = new Completer();
10 Stream<List<int>> _stream; 10 Stream<List<int>> _stream;
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 class _HttpOutboundConsumer implements StreamConsumer { 539 class _HttpOutboundConsumer implements StreamConsumer {
540 final _HttpOutboundMessage _outbound; 540 final _HttpOutboundMessage _outbound;
541 StreamController _controller; 541 StreamController _controller;
542 StreamSubscription _subscription; 542 StreamSubscription _subscription;
543 Completer _closeCompleter = new Completer(); 543 Completer _closeCompleter = new Completer();
544 Completer _completer; 544 Completer _completer;
545 545
546 _HttpOutboundConsumer(_HttpOutboundMessage this._outbound); 546 _HttpOutboundConsumer(_HttpOutboundMessage this._outbound);
547 547
548 void _onPause() { 548 void _onPause() {
549 if (_controller.isPaused) { 549 _subscription.pause();
550 _subscription.pause(); 550 }
551 } else { 551 void _onResume() {
552 _subscription.resume(); 552 _subscription.resume();
553 }
554 } 553 }
555 554
556 void _onListen() { 555 void _onCancel() {
557 if (!_controller.hasListener && _subscription != null) { 556 if (_subscription != null) {
558 _subscription.cancel(); 557 StreamSubscription subscription = _subscription;
558 _subscription = null;
559 subscription.cancel();
559 } 560 }
560 } 561 }
561 562
562 _ensureController() { 563 _ensureController() {
563 if (_controller != null) return; 564 if (_controller != null) return;
564 _controller = new StreamController(onPause: _onPause, 565 _controller = new StreamController(onPause: _onPause,
565 onResume: _onPause, 566 onResume: _onResume,
566 onListen: _onListen, 567 onCancel: _onCancel);
567 onCancel: _onListen);
568 _outbound._addStream(_controller.stream) 568 _outbound._addStream(_controller.stream)
569 .then((_) { 569 .then((_) {
570 _onListen(); // Make sure we unsubscribe. 570 _onCancel(); // Make sure we unsubscribe.
571 _done(); 571 _done();
572 _closeCompleter.complete(_outbound); 572 _closeCompleter.complete(_outbound);
573 }, 573 },
574 onError: (error) { 574 onError: (error) {
575 if (!_done(error)) { 575 if (!_done(error)) {
576 _closeCompleter.completeError(error); 576 _closeCompleter.completeError(error);
577 } 577 }
578 }); 578 });
579 } 579 }
580 580
(...skipping 1731 matching lines...) Expand 10 before | Expand all | Expand 10 after
2312 2312
2313 2313
2314 class _RedirectInfo implements RedirectInfo { 2314 class _RedirectInfo implements RedirectInfo {
2315 const _RedirectInfo(int this.statusCode, 2315 const _RedirectInfo(int this.statusCode,
2316 String this.method, 2316 String this.method,
2317 Uri this.location); 2317 Uri this.location);
2318 final int statusCode; 2318 final int statusCode;
2319 final String method; 2319 final String method;
2320 final Uri location; 2320 final Uri location;
2321 } 2321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698