what-the-bank/sources/io/grpc/stub/StreamObservers.java

43 lines
1.6 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package io.grpc.stub;
import com.google.common.base.Preconditions;
import java.util.Iterator;
/* loaded from: classes6.dex */
public final class StreamObservers {
public static <V> void copyWithFlowControl(Iterator<V> it, CallStreamObserver<V> callStreamObserver) {
Preconditions.checkNotNull(it, "source");
Preconditions.checkNotNull(callStreamObserver, "target");
callStreamObserver.setOnReadyHandler(new Runnable(callStreamObserver, it) { // from class: io.grpc.stub.StreamObservers.1FlowControllingOnReadyHandler
private boolean completed;
final Iterator val$source;
final CallStreamObserver val$target;
{
this.val$target = callStreamObserver;
this.val$source = it;
}
@Override // java.lang.Runnable
public final void run() {
if (this.completed) {
return;
}
while (this.val$target.isReady() && this.val$source.hasNext()) {
this.val$target.onNext(this.val$source.next());
}
if (this.val$source.hasNext()) {
return;
}
this.completed = true;
this.val$target.onCompleted();
}
});
}
public static <V> void copyWithFlowControl(Iterable<V> iterable, CallStreamObserver<V> callStreamObserver) {
Preconditions.checkNotNull(iterable, "source");
copyWithFlowControl(iterable.iterator(), callStreamObserver);
}
}