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

Side by Side Diff: sdk/lib/async/stream_pipe.dart

Issue 11740027: Rename unsubscribe to cancel. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Fix error message. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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.async; 5 // part of dart.async;
6 6
7 /** 7 /**
8 * A pipe between two streams. 8 * A pipe between two streams.
9 * 9 *
10 * The default pipe subscribes to the [source] and sends on the 10 * The default pipe subscribes to the [source] and sends on the
11 * [stream]. 11 * [stream].
12 * 12 *
13 * The events are passed through the [_handleData], [_handleError] and 13 * The events are passed through the [_handleData], [_handleError] and
14 * [_handleDone] methods. Subclasses are supposed to add handling of some of 14 * [_handleDone] methods. Subclasses are supposed to add handling of some of
15 * the events by overriding these methods. 15 * the events by overriding these methods.
16 * 16 *
17 * This class is intended for internal use only. Users can use the [PipeStream] 17 * This class is intended for internal use only. Users can use the [PipeStream]
18 * to configure similar behavior. 18 * to configure similar behavior.
19 */ 19 */
20 abstract class _ForwardingStream<S, T> extends _MultiStreamImpl<T> 20 abstract class _ForwardingStream<S, T> extends _MultiStreamImpl<T>
21 implements StreamChain<S, T> { 21 implements StreamChain<S, T> {
22 Stream<S> _source = null; 22 Stream<S> _source = null;
23 StreamSubscription _subscription = null; 23 StreamSubscription _subscription = null;
24 24
25 StreamController<T> _createController() { 25 StreamController<T> _createController() {
26 return new _BaseForwardingController<T>(this); 26 return new _BaseForwardingController<T>(this);
27 } 27 }
28 28
29 void _subscribeToSource() { 29 void _subscribeToSource() {
30 _subscription = _source.subscribe(onData: this._handleData, 30 _subscription = _source.listen(this._handleData,
31 onError: this._handleError, 31 onError: this._handleError,
32 onDone: this._handleDone); 32 onDone: this._handleDone);
33 if (_isPaused) { 33 if (_isPaused) {
34 _subscription.pause(); 34 _subscription.pause();
35 } 35 }
36 } 36 }
37 37
38 Stream<T> bind(Stream<S> source) { 38 Stream<T> bind(Stream<S> source) {
39 assert(_source == null); 39 assert(_source == null);
40 _source = source; 40 _source = source;
41 if (_hasSubscribers) { 41 if (_hasSubscribers) {
42 _subscribeToSource(); 42 _subscribeToSource();
43 } 43 }
44 return this; 44 return this;
45 } 45 }
46 46
47 /** 47 /**
48 * Subscribe or unsubscribe on [source] depending on whether 48 * Subscribe or unsubscribe on [source] depending on whether
49 * [stream] has subscribers. 49 * [stream] has subscribers.
50 */ 50 */
51 void _onSubscriptionStateChange() { 51 void _onSubscriptionStateChange() {
52 if (_hasSubscribers) { 52 if (_hasSubscribers) {
53 assert(_subscription == null); 53 assert(_subscription == null);
54 if (_source != null) { 54 if (_source != null) {
55 _subscribeToSource(); 55 _subscribeToSource();
56 } 56 }
57 } else { 57 } else {
58 if (_subscription != null) { 58 if (_subscription != null) {
59 _subscription.unsubscribe(); 59 _subscription.cancel();
60 _subscription = null; 60 _subscription = null;
61 } 61 }
62 } 62 }
63 } 63 }
64 64
65 void _onPauseStateChange() { 65 void _onPauseStateChange() {
66 if (_subscription == null) return; 66 if (_subscription == null) return;
67 if (isPaused) { 67 if (isPaused) {
68 _subscription.pause(); 68 _subscription.pause();
69 } else { 69 } else {
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 _signalError(new AsyncError(e, s)); 451 _signalError(new AsyncError(e, s));
452 return null; 452 return null;
453 } 453 }
454 if (!isEqual) { 454 if (!isEqual) {
455 _add(inputEvent); 455 _add(inputEvent);
456 _previous = inputEvent; 456 _previous = inputEvent;
457 } 457 }
458 } 458 }
459 } 459 }
460 } 460 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698