Skip to content

Commit

Permalink
[doc] Document usage of Mono.zip() along with empty-completed publish…
Browse files Browse the repository at this point in the history
…ers (#3306)

Added emphasis on the act of subscribing.
Fixes #3306
Author: Roman Zandler <[email protected]>
  • Loading branch information
RomaKudryavtsev committed Jun 27, 2023
1 parent 635269b commit 72d572a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/asciidoc/faq.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ myMethod.emptySequenceForKey("a") // this method returns empty Mono<String>
[[faq.monoZipEmptyCompletion]]
== Using `zip` along with empty-completed publishers

When using the `zip` operator along with empty-completed publishers, it is important to be aware of the following behavior.
When using the `zip` operator along with empty-completed publishers (i.e., publishers completing without emitting an item), it is important to be aware of the following behavior.

Consider the following test case:

Expand All @@ -185,7 +185,7 @@ Consider the following test case:
----
====

While in this case the resulting `zippedMono` does not complete immediately upon empty completion of `mono1`, such behaviour is not guaranteed for all cases. For instance, consider the following test case:
While in this case the resulting `zippedMono` subscribes to both `mono1` and `mono2`, such behaviour is not guaranteed for all cases. For instance, consider the following test case:

====
[source,java]
Expand All @@ -211,11 +211,11 @@ While in this case the resulting `zippedMono` does not complete immediately upon
}
----
====
In this case upon empty completion of `mono1`, `zippedMono` completes immediately.
In this case upon empty completion of `mono1`, `zippedMono` completes immediately and does not subscribe to `mono2` and `mono3`.

In cases where `zip` operator is used to combine empty-completed publishers, it is therefore not guaranteed that the resulting publisher will complete only upon completion of all publishers to be combined. In other words, while in some cases this behaviour might be different, it is not guaranteed that the resulting publisher will not complete immediately upon empty completion of the first publisher to be zipped.
Therefore, in cases where `zip` operator is used to combine empty-completed publishers, it is not guaranteed that the resulting publisher will subscribe to all the empty-completed publishers.

If it is necessary to keep the semantics as shown in the second test case, consider using `singleOptional` operator, as demonstrated in the test case below:
If it is necessary to keep the semantics as shown in the second test case and to ensure subscription to all the publishers to be zipped, consider using `singleOptional` operator, as demonstrated in the test case below:

====
[source,java]
Expand Down

0 comments on commit 72d572a

Please sign in to comment.