Hot versus Cold publishers

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 2The 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 ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.