com.infomaximum.cluster.graphql.subscription.SingleSubscriber Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cluster-graphql Show documentation
Show all versions of cluster-graphql Show documentation
Library for creating a light cluster
The newest version!
package com.infomaximum.cluster.graphql.subscription;
import com.infomaximum.cluster.graphql.executor.struct.GExecutionResult;
import graphql.ExecutionResult;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Flow;
public class SingleSubscriber implements Flow.Subscriber {
private final CompletableFuture completableFuture;
private Flow.Subscription subscription;
public SingleSubscriber() {
this.completableFuture = new CompletableFuture();
}
@Override
public void onSubscribe(Flow.Subscription subscription) {
this.subscription = subscription;
subscription.request(1);
}
@Override
public void onNext(Object nextValue) {
subscription.cancel();//Сразу же отписываемся
completableFuture.complete(new GExecutionResult((ExecutionResult) nextValue));
}
@Override
public void onError(Throwable throwable) {
subscription.cancel();
completableFuture.completeExceptionally(throwable);
}
@Override
public void onComplete() {
}
public CompletableFuture getCompletableFuture() {
return completableFuture;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy