1 /* 2 * Copyright 2024 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.webkit; 18 19 import androidx.annotation.NonNull; 20 21 /** 22 * Callback interface intended for use when an asynchronous operation may result in a failure. 23 * 24 * This interface may be used in cases where an asynchronous API may complete either with a value 25 * or with a {@link Throwable} that indicates an error. 26 * @param <T> The type of the result that's being sent. 27 * @param <E> The type of the {@link Throwable} that contains more information about the error. 28 * 29 * This interface serves the same purpose as 30 * <a href="https://developer.android.com/reference/android/os/OutcomeReceiver"> 31 * android.os.OutcomeReceiver</a>, but can be used on API versions before 31. 32 * 33 * TODO(b/380060342): To be removed once we release androidx.core.os.OutcomeReceiverCompat. 34 */ 35 @Profile.ExperimentalUrlPrefetch 36 public interface OutcomeReceiverCompat<T, E extends Throwable> { 37 /** 38 * Called when the asynchronous operation succeeds and delivers a result value. 39 * @param result The value delivered by the asynchronous operation. 40 */ onResult(T result)41 void onResult(T result); 42 43 /** 44 * Called when the asynchronous operation fails. The mode of failure is indicated by the 45 * {@link Throwable} passed as an argument to this method. 46 * @param error A subclass of {@link Throwable} with more details about the error that occurred. 47 */ onError(@onNull E error)48 default void onError(@NonNull E error) {} 49 } 50