public final class

ResolvableFuture<V>

extends AbstractResolvableFuture<java.lang.Object>

 java.lang.Object

androidx.media2.session.futures.AbstractResolvableFuture<java.lang.Object>

↳androidx.media2.session.futures.ResolvableFuture<V>

Overview

An AndroidX version of Guava's SettableFuture.

A whose result can be set by a ResolvableFuture.set(V), ResolvableFuture.setException(Throwable) or ResolvableFuture call. It can also, like any other Future, be cancelled.

If your needs are more complex than ResolvableFuture supports, use AbstractResolvableFuture, which offers an extensible version of the API.

Summary

Methods
public static ResolvableFuture<java.lang.Object>create()

Creates a new ResolvableFuture that can be completed or cancelled by a later method call.

protected booleanset(java.lang.Object value)

Sets the result of this Future unless this Future has already been cancelled or set (including set asynchronously).

protected booleansetException(java.lang.Throwable throwable)

Sets the failed result of this Future unless this Future has already been cancelled or set (including set asynchronously).

protected booleansetFuture(<any> future)

Sets the result of this Future to match the supplied input Future once the supplied Future is done, unless this Future has already been cancelled or set (including "set asynchronously," defined below).

from AbstractResolvableFuture<V>addListener, afterDone, cancel, get, get, interruptTask, isCancelled, isDone, pendingToString, toString, wasInterrupted
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Methods

public static ResolvableFuture<java.lang.Object> create()

Creates a new ResolvableFuture that can be completed or cancelled by a later method call.

protected boolean set(java.lang.Object value)

Sets the result of this Future unless this Future has already been cancelled or set (including set asynchronously). When a call to this method returns, the Future is guaranteed to be done only if the call was accepted (in which case it returns true). If it returns false, the Future may have previously been set asynchronously, in which case its result may not be known yet. That result, though not yet known, cannot be overridden by a call to a set* method, only by a call to AbstractResolvableFuture.cancel(boolean).

Parameters:

value: the value to be used as the result

Returns:

true if the attempt was accepted, completing the Future

protected boolean setException(java.lang.Throwable throwable)

Sets the failed result of this Future unless this Future has already been cancelled or set (including set asynchronously). When a call to this method returns, the Future is guaranteed to be done only if the call was accepted (in which case it returns true). If it returns false, the Future may have previously been set asynchronously, in which case its result may not be known yet. That result, though not yet known, cannot be overridden by a call to a set* method, only by a call to AbstractResolvableFuture.cancel(boolean).

Parameters:

throwable: the exception to be used as the failed result

Returns:

true if the attempt was accepted, completing the Future

protected boolean setFuture(<any> future)

Sets the result of this Future to match the supplied input Future once the supplied Future is done, unless this Future has already been cancelled or set (including "set asynchronously," defined below).

If the supplied future is done when this method is called and the call is accepted, then this future is guaranteed to have been completed with the supplied future by the time this method returns. If the supplied future is not done and the call is accepted, then the future will be set asynchronously. Note that such a result, though not yet known, cannot be overridden by a call to a set* method, only by a call to AbstractResolvableFuture.cancel(boolean).

If the call setFuture(delegate) is accepted and this Future is later cancelled, cancellation will be propagated to delegate. Additionally, any call to setFuture after any cancellation will propagate cancellation to the supplied Future.

Note that, even if the supplied future is cancelled and it causes this future to complete, it will never trigger interruption behavior. In particular, it will not cause this future to invoke the AbstractResolvableFuture.interruptTask() method, and the AbstractResolvableFuture.wasInterrupted() method will not return true.

Parameters:

future: the future to delegate to

Returns:

true if the attempt was accepted, indicating that the Future was not previously cancelled or set.

Since: 19.0

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.media2.session.futures;


import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;

import com.google.common.util.concurrent.ListenableFuture;

/**
 * An AndroidX version of Guava's {@code SettableFuture}.
 * <p>
 * A {@link ListenableFuture} whose result can be set by a {@link #set(Object)}, {@link
 * #setException(Throwable)} or {@link #setFuture(ListenableFuture)} call. It can also, like any
 * other {@code Future}, be {@linkplain #cancel cancelled}.
 * <p>
 * If your needs are more complex than {@code ResolvableFuture} supports, use {@link
 * AbstractResolvableFuture}, which offers an extensible version of the API.
 *
 * @hide
 * @author Sven Mawson
 */
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public final class ResolvableFuture<V> extends AbstractResolvableFuture<V> {
    /**
     * Creates a new {@code ResolvableFuture} that can be completed or cancelled by a later method
     * call.
     */
    public static <V> ResolvableFuture<V> create() {
        return new ResolvableFuture<>();
    }

    @Override
    public boolean set(@Nullable V value) {
        return super.set(value);
    }

    @Override
    public boolean setException(Throwable throwable) {
        return super.setException(throwable);
    }

    @Override
    public boolean setFuture(ListenableFuture<? extends V> future) {
        return super.setFuture(future);
    }

    private ResolvableFuture() {
    }
}