In previous chapters, we built publishers that would start publishing data to each of the subscriber instances after subscription. The Fibonacci publisher that we created in Chapter 2, The Publisher and Subscriber APIs in a Reactor, would publish the complete Fibonacci series to each of its subscribers.
Consider the following Fibonacci code as a cold publisher:
Flux<Long> fibonacciGenerator = Flux.generate(
() -> Tuples.<Long, Long>of(0L, 1L),
(state, sink) -> {
sink.next(state.getT1());
return Tuples.of(state.getT2(), state.getT1() + state.getT2());
});
fibonacciGenerator.take(5).subscribe(t -> System.out.println("1. "+t));
fibonacciGenerator.take(5).subscribe(t -> System.out.println("2. "+t));
Publishers that start publishing data to the subscriber after subscription...