View Javadoc
1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty5.util.concurrent;
17  
18  /**
19   * Special {@link Future} which is writable.
20   */
21  public interface Promise<V> extends AsynchronousResult<V> {
22      /**
23       * Marks this promise as a success and notifies all listeners attached to the {@linkplain #asFuture() future}.
24       * <p>
25       * If it is success or failed already it will throw an {@link IllegalStateException}.
26       */
27      Promise<V> setSuccess(V result);
28  
29      /**
30       * Marks this future as a success and notifies all listeners.
31       *
32       * @return {@code true} if and only if successfully marked this promise as a success.
33       * Otherwise {@code false} because this promise is already marked as either a success or a failure.
34       */
35      boolean trySuccess(V result);
36  
37      /**
38       * Marks this promise as a failure and notifies all listeners attached to the {@linkplain #asFuture() future}.
39       * <p>
40       * If it is success or failed already it will throw an {@link IllegalStateException}.
41       */
42      Promise<V> setFailure(Throwable cause);
43  
44      /**
45       * Marks this promise as a failure and notifies all listeners.
46       *
47       * @return {@code true} if and only if successfully marked this promise as a failure.
48       * Otherwise {@code false} because this promise is already marked as either a success or a failure.
49       */
50      boolean tryFailure(Throwable cause);
51  
52      /**
53       * Make this promise impossible to cancel.
54       *
55       * @return {@code true} if and only if successfully marked this promise as uncancellable.
56       * Otherwise {@code false} if this promise has been cancelled already, or has completed.
57       */
58      boolean setUncancellable();
59  
60      /**
61       * Return the {@link Future} instance is associated with this promise.
62       * This future will be completed upon completion of this promise.
63       *
64       * @return A future instance associated with this promise.
65       */
66      Future<V> asFuture();
67  }