File tree 4 files changed +53
-14
lines changed
main/java/io/reactivex/internal/operators
test/java/io/reactivex/internal/operators
4 files changed +53
-14
lines changed Original file line number Diff line number Diff line change @@ -115,14 +115,15 @@ void cancel(RefConnection rc) {
115
115
116
116
void terminated (RefConnection rc ) {
117
117
synchronized (this ) {
118
- if (connection != null && connection == rc ) {
119
- connection = null ;
118
+ if (connection == rc ) {
120
119
if (rc .timer != null ) {
121
120
rc .timer .dispose ();
121
+ rc .timer = null ;
122
+ }
123
+ if (--rc .subscriberCount == 0 ) {
124
+ connection = null ;
125
+ source .reset ();
122
126
}
123
- }
124
- if (--rc .subscriberCount == 0 ) {
125
- source .reset ();
126
127
}
127
128
}
128
129
}
Original file line number Diff line number Diff line change @@ -112,14 +112,15 @@ void cancel(RefConnection rc) {
112
112
113
113
void terminated (RefConnection rc ) {
114
114
synchronized (this ) {
115
- if (connection != null && connection == rc ) {
116
- connection = null ;
115
+ if (connection == rc ) {
117
116
if (rc .timer != null ) {
118
117
rc .timer .dispose ();
118
+ rc .timer = null ;
119
+ }
120
+ if (--rc .subscriberCount == 0 ) {
121
+ connection = null ;
122
+ source .reset ();
119
123
}
120
- }
121
- if (--rc .subscriberCount == 0 ) {
122
- source .reset ();
123
124
}
124
125
}
125
126
}
Original file line number Diff line number Diff line change 14
14
package io .reactivex .internal .operators .flowable ;
15
15
16
16
import static org .junit .Assert .*;
17
+ import static org .mockito .ArgumentMatchers .any ;
17
18
import static org .mockito .Mockito .*;
18
19
19
20
import java .io .IOException ;
@@ -1454,4 +1455,22 @@ public void publishRefCountShallBeThreadSafe() {
1454
1455
.assertComplete ();
1455
1456
}
1456
1457
}
1457
- }
1458
+
1459
+ @ Test
1460
+ public void upstreamTerminationTriggersAnotherCancel () throws Exception {
1461
+ ReplayProcessor <Integer > rp = ReplayProcessor .create ();
1462
+ rp .onNext (1 );
1463
+ rp .onComplete ();
1464
+
1465
+ Flowable <Integer > shared = rp .share ();
1466
+
1467
+ shared
1468
+ .buffer (shared .debounce (5 , TimeUnit .SECONDS ))
1469
+ .test ()
1470
+ .assertValueCount (2 );
1471
+
1472
+ shared
1473
+ .buffer (shared .debounce (5 , TimeUnit .SECONDS ))
1474
+ .test ()
1475
+ .assertValueCount (2 );
1476
+ }}
Original file line number Diff line number Diff line change 14
14
package io .reactivex .internal .operators .observable ;
15
15
16
16
import static org .junit .Assert .*;
17
+ import static org .mockito .ArgumentMatchers .any ;
17
18
import static org .mockito .Mockito .*;
18
19
19
20
import java .io .IOException ;
22
23
import java .util .concurrent .*;
23
24
import java .util .concurrent .atomic .*;
24
25
25
- import org .junit .Test ;
26
+ import org .junit .* ;
26
27
import org .mockito .InOrder ;
27
28
28
29
import io .reactivex .*;
@@ -1267,8 +1268,6 @@ public void cancelTerminateStateExclusion() {
1267
1268
.publish ()
1268
1269
.refCount ();
1269
1270
1270
- o .cancel (null );
1271
-
1272
1271
o .cancel (new RefConnection (o ));
1273
1272
1274
1273
RefConnection rc = new RefConnection (o );
@@ -1412,4 +1411,23 @@ public void publishRefCountShallBeThreadSafe() {
1412
1411
.assertComplete ();
1413
1412
}
1414
1413
}
1414
+
1415
+ @ Test
1416
+ public void upstreamTerminationTriggersAnotherCancel () throws Exception {
1417
+ ReplaySubject <Integer > rs = ReplaySubject .create ();
1418
+ rs .onNext (1 );
1419
+ rs .onComplete ();
1420
+
1421
+ Observable <Integer > shared = rs .share ();
1422
+
1423
+ shared
1424
+ .buffer (shared .debounce (5 , TimeUnit .SECONDS ))
1425
+ .test ()
1426
+ .assertValueCount (2 );
1427
+
1428
+ shared
1429
+ .buffer (shared .debounce (5 , TimeUnit .SECONDS ))
1430
+ .test ()
1431
+ .assertValueCount (2 );
1432
+ }
1415
1433
}
You can’t perform that action at this time.
0 commit comments