125 lines
3.9 KiB
Java
125 lines
3.9 KiB
Java
package io.reactivex.internal.subscribers;
|
|
|
|
import io.reactivex.FlowableSubscriber;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.exceptions.CompositeException;
|
|
import io.reactivex.exceptions.Exceptions;
|
|
import io.reactivex.functions.Action;
|
|
import io.reactivex.functions.Consumer;
|
|
import io.reactivex.internal.functions.Functions;
|
|
import io.reactivex.internal.subscriptions.SubscriptionHelper;
|
|
import io.reactivex.observers.LambdaConsumerIntrospection;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import org.reactivestreams.Subscription;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class BoundedSubscriber<T> extends AtomicReference<Subscription> implements FlowableSubscriber<T>, Subscription, Disposable, LambdaConsumerIntrospection {
|
|
private static final long serialVersionUID = -7251123623727029452L;
|
|
final int bufferSize;
|
|
int consumed;
|
|
final int limit;
|
|
final Action onComplete;
|
|
final Consumer<? super Throwable> onError;
|
|
final Consumer<? super T> onNext;
|
|
final Consumer<? super Subscription> onSubscribe;
|
|
|
|
public BoundedSubscriber(Consumer<? super T> consumer, Consumer<? super Throwable> consumer2, Action action, Consumer<? super Subscription> consumer3, int i) {
|
|
this.onNext = consumer;
|
|
this.onError = consumer2;
|
|
this.onComplete = action;
|
|
this.onSubscribe = consumer3;
|
|
this.bufferSize = i;
|
|
this.limit = i - (i >> 2);
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscription
|
|
public void cancel() {
|
|
SubscriptionHelper.cancel(this);
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
cancel();
|
|
}
|
|
|
|
public boolean hasCustomOnError() {
|
|
return this.onError != Functions.e;
|
|
}
|
|
|
|
public boolean isDisposed() {
|
|
return get() == SubscriptionHelper.CANCELLED;
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onComplete() {
|
|
Subscription subscription = get();
|
|
SubscriptionHelper subscriptionHelper = SubscriptionHelper.CANCELLED;
|
|
if (subscription != subscriptionHelper) {
|
|
lazySet(subscriptionHelper);
|
|
try {
|
|
this.onComplete.run();
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
RxJavaPlugins.b(th);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onError(Throwable th) {
|
|
Subscription subscription = get();
|
|
SubscriptionHelper subscriptionHelper = SubscriptionHelper.CANCELLED;
|
|
if (subscription == subscriptionHelper) {
|
|
RxJavaPlugins.b(th);
|
|
return;
|
|
}
|
|
lazySet(subscriptionHelper);
|
|
try {
|
|
this.onError.accept(th);
|
|
} catch (Throwable th2) {
|
|
Exceptions.b(th2);
|
|
RxJavaPlugins.b(new CompositeException(th, th2));
|
|
}
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onNext(T t) {
|
|
if (isDisposed()) {
|
|
return;
|
|
}
|
|
try {
|
|
this.onNext.accept(t);
|
|
int i = this.consumed + 1;
|
|
if (i == this.limit) {
|
|
this.consumed = 0;
|
|
get().request(this.limit);
|
|
} else {
|
|
this.consumed = i;
|
|
}
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
get().cancel();
|
|
onError(th);
|
|
}
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onSubscribe(Subscription subscription) {
|
|
if (SubscriptionHelper.setOnce(this, subscription)) {
|
|
try {
|
|
this.onSubscribe.accept(this);
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
subscription.cancel();
|
|
onError(th);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscription
|
|
public void request(long j) {
|
|
get().request(j);
|
|
}
|
|
}
|