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 17 package android.os; 18 19 import android.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 <R> 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 public interface OutcomeReceiver<R, E extends Throwable> { 30 /** 31 * Called when the asynchronous operation succeeds and delivers a result value. 32 * @param result The value delivered by the asynchronous operation. 33 */ onResult(@onNull R result)34 void onResult(@NonNull R result); 35 36 /** 37 * Called when the asynchronous operation fails. The mode of failure is indicated by the 38 * {@link Throwable} passed as an argument to this method. 39 * @param error A subclass of {@link Throwable} with more details about the error that occurred. 40 */ onError(@onNull E error)41 default void onError(@NonNull E error) {} 42 } 43