• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.car.util.concurrent;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 
21 import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.Executor;
23 import java.util.concurrent.TimeUnit;
24 import java.util.concurrent.TimeoutException;
25 import java.util.function.BiConsumer;
26 
27 /**
28  * Custom {@code Future} that provides a way to be handled asynchronously.
29  *
30  * <p><b>Note: it doesn't extend {@link java.util.concurrent.Future} because it's implemented by
31  * {@code AndroidFuture}, which doesn't propagate
32  * {@link java.util.concurrent.Future#cancel(boolean)} to the remote object.
33  *
34  * @param <T> type returned by the {@code Future}.
35  *
36  * @hide
37  */
38 public interface AsyncFuture<T> {
39 
40     /**
41      * See {@link java.util.concurrent.Future#get()}.
42      */
43     @Nullable
get()44     T get() throws InterruptedException, ExecutionException;
45 
46     /**
47      * See {@link java.util.concurrent.Future#get(long, TimeUnit).
48      */
49     @Nullable
get(long timeout, @NonNull TimeUnit unit)50     T get(long timeout, @NonNull TimeUnit unit)
51             throws InterruptedException, ExecutionException, TimeoutException;
52 
53     /**
54      * See {@link java.util.concurrent.CompletableFuture#whenCompleteAsync(BiConsumer, Executor).
55      */
56     @NonNull
whenCompleteAsync(@onNull BiConsumer<? super T, ? super Throwable> action, @NonNull Executor executor)57     AsyncFuture<T> whenCompleteAsync(@NonNull BiConsumer<? super T, ? super Throwable> action,
58             @NonNull Executor executor);
59 }
60