package io.grpc.stub; import com.google.common.base.Preconditions; import java.util.Iterator; /* loaded from: classes6.dex */ public final class StreamObservers { public static void copyWithFlowControl(Iterator it, CallStreamObserver 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 void copyWithFlowControl(Iterable iterable, CallStreamObserver callStreamObserver) { Preconditions.checkNotNull(iterable, "source"); copyWithFlowControl(iterable.iterator(), callStreamObserver); } }