@@ -99,6 +99,7 @@ public static <T> UnicastMonoProcessor<T> create(MonoLifecycleHandler<T> lifecyc
99
99
UnicastMonoProcessor .class , Subscription .class , "subscription" );
100
100
101
101
CoreSubscriber <? super O > actual ;
102
+ boolean hasDownstream = false ;
102
103
103
104
Throwable error ;
104
105
O value ;
@@ -185,7 +186,7 @@ private void complete(O v) {
185
186
if (state == HAS_REQUEST_NO_RESULT ) {
186
187
if (STATE .compareAndSet (this , HAS_REQUEST_NO_RESULT , HAS_REQUEST_HAS_RESULT )) {
187
188
final Subscriber <? super O > a = actual ;
188
- actual = null ;
189
+ hasDownstream = false ;
189
190
value = null ;
190
191
lifecycleHandler .doOnTerminal (SignalType .ON_COMPLETE , v , null );
191
192
a .onNext (v );
@@ -222,7 +223,7 @@ private void complete() {
222
223
if (state == HAS_REQUEST_NO_RESULT || state == NO_REQUEST_NO_RESULT ) {
223
224
if (STATE .compareAndSet (this , state , HAS_REQUEST_HAS_RESULT )) {
224
225
final Subscriber <? super O > a = actual ;
225
- actual = null ;
226
+ hasDownstream = false ;
226
227
lifecycleHandler .doOnTerminal (SignalType .ON_COMPLETE , null , null );
227
228
a .onComplete ();
228
229
return ;
@@ -256,7 +257,7 @@ private void complete(Throwable e) {
256
257
if (state == HAS_REQUEST_NO_RESULT || state == NO_REQUEST_NO_RESULT ) {
257
258
if (STATE .compareAndSet (this , state , HAS_REQUEST_HAS_RESULT )) {
258
259
final Subscriber <? super O > a = actual ;
259
- actual = null ;
260
+ hasDownstream = false ;
260
261
lifecycleHandler .doOnTerminal (SignalType .ON_ERROR , null , e );
261
262
a .onError (e );
262
263
return ;
@@ -278,6 +279,7 @@ public void subscribe(CoreSubscriber<? super O> actual) {
278
279
279
280
lh .doOnSubscribe ();
280
281
282
+ this .hasDownstream = true ;
281
283
this .actual = actual ;
282
284
283
285
int state = this .state ;
@@ -303,7 +305,7 @@ public void subscribe(CoreSubscriber<? super O> actual) {
303
305
// no value
304
306
// e.g. [onError / onComplete / dispose] only
305
307
if (state == NO_REQUEST_HAS_RESULT && this .value == null ) {
306
- this .actual = null ;
308
+ this .hasDownstream = false ;
307
309
Throwable e = this .error ;
308
310
// barrier to flush changes
309
311
STATE .set (this , HAS_REQUEST_HAS_RESULT );
@@ -340,7 +342,7 @@ public final void request(long n) {
340
342
if (STATE .compareAndSet (this , NO_REQUEST_HAS_RESULT , HAS_REQUEST_HAS_RESULT )) {
341
343
final Subscriber <? super O > a = actual ;
342
344
final O v = value ;
343
- actual = null ;
345
+ hasDownstream = false ;
344
346
value = null ;
345
347
lifecycleHandler .doOnTerminal (SignalType .ON_COMPLETE , v , null );
346
348
a .onNext (v );
@@ -360,7 +362,7 @@ public final void cancel() {
360
362
if (STATE .getAndSet (this , CANCELLED ) <= HAS_REQUEST_NO_RESULT ) {
361
363
Operators .onDiscard (value , currentContext ());
362
364
value = null ;
363
- actual = null ;
365
+ hasDownstream = false ;
364
366
lifecycleHandler .doOnTerminal (SignalType .CANCEL , null , null );
365
367
final Subscription s = UPSTREAM .getAndSet (this , Operators .cancelledSubscription ());
366
368
if (s != null && s != Operators .cancelledSubscription ()) {
@@ -502,6 +504,6 @@ public Object scanUnsafe(Attr key) {
502
504
* @return true if any {@link Subscriber} is actively subscribed
503
505
*/
504
506
public final boolean hasDownstream () {
505
- return state > NO_SUBSCRIBER_HAS_RESULT && actual != null ;
507
+ return state > NO_SUBSCRIBER_HAS_RESULT && hasDownstream ;
506
508
}
507
509
}
0 commit comments