| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.internal.operators.maybe; |
| 15 |
|
| 16 |
import java.util.concurrent.atomic.AtomicReference; |
| 17 |
|
| 18 |
import io.reactivex.rxjava3.core.*; |
| 19 |
import io.reactivex.rxjava3.disposables.Disposable; |
| 20 |
import io.reactivex.rxjava3.internal.disposables.DisposableHelper; |
| 21 |
|
| 22 |
public final class MaybeDelayWithCompletable<T> extends Maybe<T> { |
| 23 |
|
| 24 |
final MaybeSource<T> source; |
| 25 |
|
| 26 |
final CompletableSource other; |
| 27 |
|
| 28 |
public MaybeDelayWithCompletable(MaybeSource<T> source, CompletableSource other) { |
| 29 |
this.source = source; |
| 30 |
this.other = other; |
| 31 |
} |
| 32 |
|
| 33 |
@Override |
| 34 |
protected void subscribeActual(MaybeObserver<? super T> observer) { |
| 35 |
other.subscribe(new OtherObserver<>(observer, source)); |
| 36 |
} |
| 37 |
|
| 38 |
static final class OtherObserver<T> |
| 39 |
extends AtomicReference<Disposable> |
| 40 |
implements CompletableObserver, Disposable { |
| 41 |
private static final long serialVersionUID = 703409937383992161L; |
| 42 |
|
| 43 |
final MaybeObserver<? super T> downstream; |
| 44 |
|
| 45 |
final MaybeSource<T> source; |
| 46 |
|
| 47 |
OtherObserver(MaybeObserver<? super T> actual, MaybeSource<T> source) { |
| 48 |
this.downstream = actual; |
| 49 |
this.source = source; |
| 50 |
} |
| 51 |
|
| 52 |
@Override |
| 53 |
public void onSubscribe(Disposable d) { |
| 54 |
if (DisposableHelper.setOnce(this, d)) { |
| 55 |
|
| 56 |
downstream.onSubscribe(this); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public void onError(Throwable e) { |
| 62 |
downstream.onError(e); |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
public void onComplete() { |
| 67 |
source.subscribe(new DelayWithMainObserver<>(this, downstream)); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public void dispose() { |
| 72 |
DisposableHelper.dispose(this); |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public boolean isDisposed() { |
| 77 |
return DisposableHelper.isDisposed(get()); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
static final class DelayWithMainObserver<T> implements MaybeObserver<T> { |
| 82 |
|
| 83 |
final AtomicReference<Disposable> parent; |
| 84 |
|
| 85 |
final MaybeObserver<? super T> downstream; |
| 86 |
|
| 87 |
DelayWithMainObserver(AtomicReference<Disposable> parent, MaybeObserver<? super T> downstream) { |
| 88 |
this.parent = parent; |
| 89 |
this.downstream = downstream; |
| 90 |
} |
| 91 |
|
| 92 |
@Override |
| 93 |
public void onSubscribe(Disposable d) { |
| 94 |
DisposableHelper.replace(parent, d); |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
public void onSuccess(T value) { |
| 99 |
downstream.onSuccess(value); |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
public void onError(Throwable e) { |
| 104 |
downstream.onError(e); |
| 105 |
} |
| 106 |
|
| 107 |
@Override |
| 108 |
public void onComplete() { |
| 109 |
downstream.onComplete(); |
| 110 |
} |
| 111 |
} |
| 112 |
} |