@@ -0,0 +1,1999 @@
+/*******************************************************************************%0A * Copyright (C) 2017 Push Technology Ltd.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A *******************************************************************************/%0A%0Apackage com.pushtechnology.adapters.rest.adapter;%0A%0Aimport java.util.concurrent.CompletableFuture;%0Aimport java.util.function.Function;%0A%0A/**%0A * A deferred function that may complete asynchronously.%0A *%0A * @author Matt Champion 14/01/2018%0A */%0Apublic interface AsyncFunction%3CT, U%3E extends Function%3CT, CompletableFuture%3CU%3E%3E %7B%0A    /**%0A     * Create an asyn function from an exceptional function.%0A     */%0A    static %3CT, U, E extends Exception%3E AsyncFunction%3CT, U%3E create(ExceptionalFunction%3CT, U, E%3E func) %7B%0A        return value -%3E %7B%0A            try %7B%0A                return CompletableFuture.completedFuture(func.apply(value));%0A            %7D%0A            catch (Exception e) %7B%0A                final CompletableFuture%3CU%3E future = new CompletableFuture%3C%3E();%0A                future.completeExceptionally(e);%0A                return future;%0A            %7D%0A        %7D;%0A    %7D%0A%0A    /**%0A     * A function that can fail to be applied.%0A     */%0A    interface ExceptionalFunction%3CT, U, E extends Exception%3E %7B%0A        /**%0A         * Apply the function.%0A         * @param value the value to apply the function to%0A         * @return the result%0A         * @throws E an exception if the function cannot be applied%0A         */%0A        U apply(T value) throws E;%0A    %7D%0A%7D%0A

Add an asynchronous function.