Skip to content

Commit 515e680

Browse files
authored
Extend docs on double-completion using SubscribableListener (#133391)
The `SubscribableListener` test suite asserts that the listener passed to the callbacks provided to `newForked` and `andThen` is identical to the returned listener, and therefore a `SubscribableListener`, so it is acceptable to complete these things racily. This commit adds a note to the relevant JavaDocs clarifying this point.
1 parent 7f39b19 commit 515e680

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

server/src/main/java/org/elasticsearch/action/support/SubscribableListener.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public static <T> SubscribableListener<T> newFailed(Exception exception) {
129129
/**
130130
* Create a {@link SubscribableListener}, fork a computation to complete it, and return the listener. If the forking itself throws an
131131
* exception then the exception is caught and fed to the returned listener.
132+
* <p>
133+
* The listener passed to {@code fork} is the returned {@link SubscribableListener}. In particular, it is valid to complete this
134+
* listener more than once, but all results after the first completion will be silently ignored.
132135
*/
133136
public static <T> SubscribableListener<T> newForked(CheckedConsumer<ActionListener<T>, ? extends Exception> fork) {
134137
final var listener = new SubscribableListener<T>();
@@ -448,6 +451,9 @@ public void complete(ActionListener<?> listener) {
448451
* <li>Ensure that this {@link SubscribableListener} is always completed using that executor, and</li>
449452
* <li>Invoke {@link #andThen} using that executor.</li>
450453
* </ul>
454+
* <p>
455+
* The listener passed to {@code nextStep} is the returned {@link SubscribableListener}. In particular, it is valid to complete this
456+
* listener more than once, but all results after the first completion will be silently ignored.
451457
*/
452458
public <U> SubscribableListener<U> andThen(CheckedConsumer<ActionListener<U>, ? extends Exception> nextStep) {
453459
return newForked(l -> addListener(l.delegateFailureIgnoreResponseAndWrap(nextStep)));
@@ -475,6 +481,9 @@ public <U> SubscribableListener<U> andThen(CheckedConsumer<ActionListener<U>, ?
475481
* <li>Ensure that this {@link SubscribableListener} is always completed using that executor, and</li>
476482
* <li>Invoke {@link #andThen} using that executor.</li>
477483
* </ul>
484+
* <p>
485+
* The listener passed to {@code nextStep} is the returned {@link SubscribableListener}. In particular, it is valid to complete this
486+
* listener more than once, but all results after the first completion will be silently ignored.
478487
*/
479488
public <U> SubscribableListener<U> andThen(CheckedBiConsumer<ActionListener<U>, T, ? extends Exception> nextStep) {
480489
return andThen(EsExecutors.DIRECT_EXECUTOR_SERVICE, null, nextStep);
@@ -513,6 +522,9 @@ public <U> SubscribableListener<U> andThen(CheckedBiConsumer<ActionListener<U>,
513522
* with a rejection exception on the thread which completes this listener. Likewise if this listener is completed exceptionally but
514523
* {@code executor} rejects the execution of the completion of the returned listener then the returned listener is completed with a
515524
* rejection exception on the thread which completes this listener.
525+
* <p>
526+
* The listener passed to {@code nextStep} is the returned {@link SubscribableListener}. In particular, it is valid to complete this
527+
* listener more than once, but all results after the first completion will be silently ignored.
516528
*/
517529
public <U> SubscribableListener<U> andThen(
518530
Executor executor,

0 commit comments

Comments
 (0)