The sink gets bounded to a subscriber of the publisher. It gets invoked via the consumer function, when a subscriber asks for data. For each invocation, the sink can be used to generate a maximum of one value event at a time. The sink can raise additional onCompletion or error events during the invocation.

It is important to note that the events generated by sink are synchronously consumed at the subscriber end. Let's reflect on the Fibonacci test that we wrote in the previous chapter:

Flux<Long> fibonacciGenerator = Flux.generate(        () -> Tuples.<Long, Long>of(0L, 1L),        (state, sink) -> {  ;            System.out.println("generated "+state.getT1()); return Tuples.of(state.getT2(), state.getT1() + state.getT2()); ...

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.