21
21
import io .reactivex .internal .subscriptions .SubscriptionHelper ;
22
22
23
23
/**
24
- * An abstract subscription that allows asynchronous cancellation.
24
+ * An abstract Subscriber that allows asynchronous cancellation by implementing Disposable .
25
25
*
26
- * @param <T>
26
+ * @param <T> the received value type.
27
27
*/
28
28
public abstract class DisposableSubscriber <T > implements Subscriber <T >, Disposable {
29
29
final AtomicReference <Subscription > s = new AtomicReference <Subscription >();
@@ -35,18 +35,38 @@ public final void onSubscribe(Subscription s) {
35
35
}
36
36
}
37
37
38
+ /**
39
+ * Returns the current Subscription sent to this Subscriber via onSubscribe().
40
+ * @return the current Subscription, may be null
41
+ */
38
42
protected final Subscription subscription () {
39
43
return s .get ();
40
44
}
41
45
46
+ /**
47
+ * Called once the single upstream Subscription is set via onSubscribe.
48
+ */
42
49
protected void onStart () {
43
50
s .get ().request (Long .MAX_VALUE );
44
51
}
45
52
53
+ /**
54
+ * Requests the specified amount from the upstream if its Subscription is set via
55
+ * onSubscribe already.
56
+ * <p>Note that calling this method before a Subscription is set via onSubscribe
57
+ * leads to NullPointerException and meant to be called from inside onStart or
58
+ * onNext.
59
+ * @param n the request amount, positive
60
+ */
46
61
protected final void request (long n ) {
47
62
s .get ().request (n );
48
63
}
49
64
65
+ /**
66
+ * Cancels the Subscription set via onSubscribe or makes sure a
67
+ * Subscription set asynchronously (later) is cancelled immediately.
68
+ * <p>This method is thread-safe and can be exposed as a public API.
69
+ */
50
70
protected final void cancel () {
51
71
dispose ();
52
72
}
0 commit comments