Search code examples
javareactive-programmingproject-reactor

Do multiple .repeats() do anything to a flux in project reactor?


What/is there a difference between:

flux2 = flux1.repeat().map(x -> x + 1).repeat();

and

flux2 = flux1.repeat().map(x -> x + 1);

Solution

  • As the Flux never completes because of the first repeat(), the second repeat() will never have a chance to resubscribe so it's basically a no-op.

    However, note that this is not always the case for any two repeats within a Flux chain. If between the first and the second repeat there is an operator which would complete the publisher based on some condition (e.g. take, takeUntil), then the second repeat would make the otherwise finite Flux infinite.