blob: 669d01b4d1454ec56aa3f7dc55f5e0f8e6ffbf05 [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001package org.apache.felix.dm.lambda.callbacks;
2
3import java.util.Objects;
4
5/**
Pierre De Rop11527502016-02-18 21:07:16 +00006 * Represents a callback that accepts the result of a CompletableFuture operation. The callback is invoked on a Component implementation class.
7 * The type of the class on which the callback is invoked on is represented by the T generic parameter.
8 * The type of the result of the CompletableFuture is represented by the F generic parameter.
Pierre De Ropfaca2892016-01-31 23:27:05 +00009 *
10 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
11 */
12@FunctionalInterface
Pierre De Rop11527502016-02-18 21:07:16 +000013public interface CbFuture<T, F> extends SerializableLambda {
Pierre De Ropfaca2892016-01-31 23:27:05 +000014 /**
Pierre De Rop11527502016-02-18 21:07:16 +000015 * Handles the given arguments.
16 * @param instance the Component implementation instance on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +000017 * @param future the result of a CompletableFuture operation.
18 */
Pierre De Rop11527502016-02-18 21:07:16 +000019 void accept(T instance, F future);
Pierre De Ropfaca2892016-01-31 23:27:05 +000020
Pierre De Rop11527502016-02-18 21:07:16 +000021 default CbFuture<T, F> andThen(CbFuture<? super T, F> after) {
Pierre De Ropfaca2892016-01-31 23:27:05 +000022 Objects.requireNonNull(after);
Pierre De Rop11527502016-02-18 21:07:16 +000023 return (T instance, F future) -> {
24 accept(instance, future);
25 after.accept(instance, future);
Pierre De Ropfaca2892016-01-31 23:27:05 +000026 };
27 }
28}