1 /*
2  * Copyright 2018 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 
17 package androidx.concurrent.futures;
18 
19 
20 import androidx.annotation.RestrictTo;
21 
22 import com.google.common.util.concurrent.ListenableFuture;
23 
24 import org.jspecify.annotations.NonNull;
25 import org.jspecify.annotations.Nullable;
26 
27 /**
28  * An AndroidX version of Guava's {@code SettableFuture}.
29  * <p>
30  * A {@link ListenableFuture} whose result can be set by a {@link #set(Object)}, {@link
31  * #setException(Throwable)} or {@link #setFuture(ListenableFuture)} call. It can also, like any
32  * other {@code Future}, be {@linkplain #cancel cancelled}.
33  * <p>
34  * If your needs are more complex than {@code ResolvableFuture} supports, use {@link
35  * AbstractResolvableFuture}, which offers an extensible version of the API.
36  *
37  * @author Sven Mawson
38  */
39 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
40 public final class ResolvableFuture<V> extends AbstractResolvableFuture<V> {
41     /**
42      * Creates a new {@code ResolvableFuture} that can be completed or cancelled by a later method
43      * call.
44      */
create()45     public static <V> @NonNull ResolvableFuture<V> create() {
46         return new ResolvableFuture<>();
47     }
48 
49     @Override
set(@ullable V value)50     public boolean set(@Nullable V value) {
51         return super.set(value);
52     }
53 
54     @Override
setException(@onNull Throwable throwable)55     public boolean setException(@NonNull Throwable throwable) {
56         return super.setException(throwable);
57     }
58 
59     @Override
setFuture(@onNull ListenableFuture<? extends V> future)60     public boolean setFuture(@NonNull ListenableFuture<? extends V> future) {
61         return super.setFuture(future);
62     }
63 
ResolvableFuture()64     private ResolvableFuture() {
65     }
66 }
67 
68