1 /*
2  * Copyright (C) 2018 The Dagger Authors.
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 dagger.producers.internal;
18 
19 import dagger.producers.Producer;
20 
21 /** A {@link Producer} that can be cancelled directly even if it hasn't been started. */
22 public interface CancellableProducer<T> extends Producer<T> {
23 
24   /**
25    * Cancels this producer. If {@link #get()} has already been called, the future it returns will be
26    * cancelled if possible. If not, calling {@link #get()} will return a cancelled future and will
27    * not actually start the underlying operation.
28    *
29    * @param mayInterruptIfRunning the value that should be passed to {@code Future.cancel(boolean)}
30    *     for the futures for any running tasks when cancelling them
31    */
cancel(boolean mayInterruptIfRunning)32   void cancel(boolean mayInterruptIfRunning);
33 
34   /** Returns a new view of this producer for use as a dependency of another node. */
newDependencyView()35   Producer<T> newDependencyView();
36 
37   /**
38    * Returns a new view of this producer for use as an entry point.
39    *
40    * <p>When the view's future is cancelled, the given {@code cancellableListener} will be called.
41    */
newEntryPointView(CancellationListener cancellationListener)42   Producer<T> newEntryPointView(CancellationListener cancellationListener);
43 }
44