All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.thinkerou.karate.grpc.DoneObserver Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package com.github.thinkerou.karate.grpc;

import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;

import io.grpc.stub.StreamObserver;

/**
 * DoneObserver
 * A StreamObserver holding a future which completes when the rpc terminates.
 *
 * @author thinkerou
 */
public class DoneObserver implements StreamObserver {

    private final SettableFuture doneFuture;

    DoneObserver() {
        this.doneFuture = SettableFuture.create();
    }

    @Override
    public synchronized void onCompleted() {
        doneFuture.set(null);
    }

    @Override
    public synchronized void onError(Throwable t) {
        doneFuture.setException(t);
    }

    @Override
    public void onNext(T next) {}

    /**
     * Returns a future which completes when the rpc finishes.
     * The returned future fails if the rpc fails.
     */
    ListenableFuture getCompletionFuture() {
        return doneFuture;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy