1 /* 2 * Copyright (C) 2022 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 com.android.quicksearchbox.util 17 18 /** 19 * Interface for an object that may be constructed asynchronously. In cases when the object is ready 20 * (on constructible) immediately, it provides synchronous access to it. Otherwise, the object can 21 * be sent to a [Consumer] later. 22 */ 23 interface NowOrLater<C> { 24 /** Indicates if the object is ready (or constructible synchronously). */ haveNownull25 fun haveNow(): Boolean 26 27 /** 28 * Gets the object now. Should only be called if [.haveNow] returns `true`, otherwise an 29 * [IllegalStateException] will be thrown. 30 */ 31 val now: C 32 33 /** 34 * Request the object asynchronously. This can be called even if the object is ready now, in which 35 * case the callback may be made in context. The thread on which the consumer is called back 36 * depends on the implementation. 37 */ 38 fun getLater(consumer: Consumer<in C>?) 39 } 40