File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
rxjava-core/src/main/java/rx/subscriptions Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 19
19
20
20
import rx .Observable ;
21
21
import rx .Subscription ;
22
+ import rx .util .functions .Action0 ;
22
23
23
24
/**
24
25
* Subscription that can be checked for status such as in a loop inside an {@link Observable} to exit the loop if unsubscribed.
28
29
public class BooleanSubscription implements Subscription {
29
30
30
31
private final AtomicBoolean unsubscribed = new AtomicBoolean (false );
32
+ private final Action0 action ;
33
+
34
+ public BooleanSubscription () {
35
+ action = null ;
36
+ }
37
+
38
+ private BooleanSubscription (Action0 action ) {
39
+ this .action = action ;
40
+ }
41
+
42
+ public static BooleanSubscription create () {
43
+ return new BooleanSubscription ();
44
+ }
45
+
46
+ public static BooleanSubscription create (Action0 onUnsubscribe ) {
47
+ return new BooleanSubscription (onUnsubscribe );
48
+ }
31
49
32
50
public boolean isUnsubscribed () {
33
51
return unsubscribed .get ();
34
52
}
35
53
36
54
@ Override
37
- public void unsubscribe () {
38
- unsubscribed .set (true );
55
+ public final void unsubscribe () {
56
+ if (unsubscribed .compareAndSet (false , true )) {
57
+ if (action != null ) {
58
+ action .call ();
59
+ }
60
+ }
39
61
}
40
62
41
63
}
You can’t perform that action at this time.
0 commit comments