1/*
2 * Copyright (C) 2010 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 */
16package 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 {@link Consumer} later.
22 */
23public interface NowOrLater<C> {
24
25    /**
26     * Indicates if the object is ready (or constructible synchronously).
27     */
28    boolean haveNow();
29
30    /**
31     * Gets the object now. Should only be called if {@link #haveNow()} returns {@code true},
32     * otherwise an {@link IllegalStateException} will be thrown.
33     */
34    C getNow();
35
36    /**
37     * Request the object asynchronously. This can be called even if the object is ready now, in
38     * which case the callback may be made in context. The thread on which the consumer is called
39     * back depends on the implementation.
40     */
41    void getLater(Consumer<? super C> consumer);
42
43}
44