
hu.akarnokd.rxjava3.interop.SingleV3ToSingleV1 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava3-interop Show documentation
Show all versions of rxjava3-interop Show documentation
rxjava3-interop developed by David Karnok
The newest version!
/*
* Copyright 2016-2020 David Karnok
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hu.akarnokd.rxjava3.interop;
import java.util.concurrent.atomic.AtomicReference;
/**
* Convert a V3 Single into a V1 Single, composing cancellation.
*
* @param the value type
*/
final class SingleV3ToSingleV1 implements rx.Single.OnSubscribe {
final io.reactivex.rxjava3.core.SingleSource source;
SingleV3ToSingleV1(io.reactivex.rxjava3.core.SingleSource source) {
this.source = source;
}
@Override
public void call(rx.SingleSubscriber super T> t) {
SourceSingleObserver parent = new SourceSingleObserver<>(t);
t.add(parent);
source.subscribe(parent);
}
static final class SourceSingleObserver
extends AtomicReference
implements io.reactivex.rxjava3.core.SingleObserver, rx.Subscription {
private static final long serialVersionUID = 4758098209431016997L;
final rx.SingleSubscriber super T> actual;
SourceSingleObserver(rx.SingleSubscriber super T> actual) {
this.actual = actual;
}
@Override
public void unsubscribe() {
DisposableHelper.dispose(this);
}
@Override
public boolean isUnsubscribed() {
return DisposableHelper.isDisposed(get());
}
@Override
public void onSubscribe(io.reactivex.rxjava3.disposables.Disposable d) {
DisposableHelper.setOnce(this, d);
}
@Override
public void onSuccess(T value) {
actual.onSuccess(value);
}
@Override
public void onError(Throwable e) {
actual.onError(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy