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

tech.ydb.core.operation.FailedOperation Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package tech.ydb.core.operation;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

import tech.ydb.core.Result;
import tech.ydb.core.Status;

/**
 *
 * @author Aleksandr Gorshenin
 */
class FailedOperation implements Operation {
    private final T value;
    private final Status status;

    FailedOperation(T value, Status status) {
        this.value = value;
        this.status = status;
    }

    @Override
    public String getId() {
        return null;
    }

    @Override
    public boolean isReady() {
        return true;
    }

    @Override
    public T getValue() {
        return value;
    }

    @Override
    public CompletableFuture cancel() {
        return CompletableFuture.completedFuture(status);
    }

    @Override
    public CompletableFuture forget() {
        return CompletableFuture.completedFuture(status);
    }

    @Override
    public CompletableFuture> fetch() {
        return CompletableFuture.completedFuture(Result.fail(status));
    }

    @Override
    public  Operation transform(Function func) {
        return new FailedOperation<>(func.apply(value), status);
    }

    @Override
    public String toString() {
        return "FailedOperation{status=" + status + "}";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy