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

com.yahoo.bard.webservice.util.CompletedFuture Maven / Gradle / Ivy

Go to download

Fili web service library provides core capabilities for RESTful aggregation navigation, query planning and metadata

There is a newer version: 1.1.13
Show newest version
// Copyright 2017 Yahoo Inc.
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms.
package com.yahoo.bard.webservice.util;

import java.util.concurrent.CompletableFuture;

/**
 * A utility class to create futures which have already been completed and will return as soon as it is called.
 */
public class CompletedFuture {

    /**
     * Private constructor - all methods static.
     */
    private CompletedFuture() {
        // Intentionally left blank.
    }

    /**
     * Creates a completed {@link java.util.concurrent.Future} which will throw the given exception.
     *
     * @param throwable  A throwable to be thrown upon calling {@link java.util.concurrent.Future#get()} and related
     * methods.
     * @param   The type to be returned by this future
     *
     * @return a completed {@link CompletableFuture} which will fail and throw an exception.
     */
    public static  CompletableFuture throwing(Throwable throwable) {
        CompletableFuture completedFuture = CompletableFuture.supplyAsync(() -> null);
        completedFuture.completeExceptionally(throwable);
        return completedFuture;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy