| 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.single; |
| 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 |
import io.reactivex.rxjava3.internal.observers.ResumeSingleObserver; |
| 22 |
|
| 23 |
public final class SingleDelayWithSingle<T, U> extends Single<T> { |
| 24 |
|
| 25 |
final SingleSource<T> source; |
| 26 |
|
| 27 |
final SingleSource<U> other; |
| 28 |
|
| 29 |
public SingleDelayWithSingle(SingleSource<T> source, SingleSource<U> other) { |
| 30 |
this.source = source; |
| 31 |
this.other = other; |
| 32 |
} |
| 33 |
|
| 34 |
@Override |
| 35 |
protected void subscribeActual(SingleObserver<? super T> observer) { |
| 36 |
other.subscribe(new OtherObserver<>(observer, source)); |
| 37 |
} |
| 38 |
|
| 39 |
static final class OtherObserver<T, U> |
| 40 |
extends AtomicReference<Disposable> |
| 41 |
implements SingleObserver<U>, Disposable { |
| 42 |
|
| 43 |
private static final long serialVersionUID = -8565274649390031272L; |
| 44 |
|
| 45 |
final SingleObserver<? super T> downstream; |
| 46 |
|
| 47 |
final SingleSource<T> source; |
| 48 |
|
| 49 |
OtherObserver(SingleObserver<? super T> actual, SingleSource<T> source) { |
| 50 |
this.downstream = actual; |
| 51 |
this.source = source; |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public void onSubscribe(Disposable d) { |
| 56 |
if (DisposableHelper.setOnce(this, d)) { |
| 57 |
|
| 58 |
downstream.onSubscribe(this); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public void onSuccess(U value) { |
| 64 |
source.subscribe(new ResumeSingleObserver<>(this, downstream)); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public void onError(Throwable e) { |
| 69 |
downstream.onError(e); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public void dispose() { |
| 74 |
DisposableHelper.dispose(this); |
| 75 |
} |
| 76 |
|
| 77 |
@Override |
| 78 |
public boolean isDisposed() { |
| 79 |
return DisposableHelper.isDisposed(get()); |
| 80 |
} |
| 81 |
} |
| 82 |
} |