• 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 import android.annotation.TestApi;
21 import android.car.annotation.AddedInOrBefore;
22 
23 import java.util.concurrent.ExecutionException;
24 import java.util.concurrent.Executor;
25 import java.util.concurrent.TimeUnit;
26 import java.util.concurrent.TimeoutException;
27 import java.util.function.BiConsumer;
28 
29 /**
30  * Custom {@code Future} that provides a way to be handled asynchronously.
31  *
32  * <p><b>Note: it doesn't extend {@link java.util.concurrent.Future} because it's implemented by
33  * {@code AndroidFuture}, which doesn't propagate
34  * {@link java.util.concurrent.Future#cancel(boolean)} to the remote object.
35  *
36  * @param <T> type returned by the {@code Future}.
37  *
38  * @hide
39  */
40 @TestApi
41 public interface AsyncFuture<T> {
42 
43     /**
44      * See {@link java.util.concurrent.Future#get()}.
45      */
46     @Nullable
47     @AddedInOrBefore(majorVersion = 33)
get()48     T get() throws InterruptedException, ExecutionException;
49 
50     /**
51      * See {@link java.util.concurrent.Future#get(long, TimeUnit).
52      */
53     @Nullable
54     @AddedInOrBefore(majorVersion = 33)
get(long timeout, @NonNull TimeUnit unit)55     T get(long timeout, @NonNull TimeUnit unit)
56             throws InterruptedException, ExecutionException, TimeoutException;
57 
58     /**
59      * See {@link java.util.concurrent.CompletableFuture#whenCompleteAsync(BiConsumer, Executor).
60      */
61     @NonNull
62     @AddedInOrBefore(majorVersion = 33)
whenCompleteAsync(@onNull BiConsumer<? super T, ? super Throwable> action, @NonNull Executor executor)63     AsyncFuture<T> whenCompleteAsync(@NonNull BiConsumer<? super T, ? super Throwable> action,
64             @NonNull Executor executor);
65 }
66