SynchronousSink

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) -> {            sink.next(state.getT1());            System.out.println("generated "+state.getT1()); return Tuples.of(state.getT2(), state.getT1() + state.getT2()); ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.