Java Reactor Flux/Mono, when does doOnNext get triggered before or after element is emitted?

dvsakgec :

I have this confusion, when does doOnNext is triggered before or after of element emission by Publisher (Flux/Mono).

Michael Berry :

It's after the publication of the element - and it has to be after by definition, otherwise the Consumer passed to doOnNext wouldn't have access to the element emitted.

However, doOnNext() is called before the subscriber. For example:

Flux.just("first", "second")
        .doOnNext(x -> System.out.println(x + " onNext"))
        .subscribe(System.out::println);

...would output:

first onNext
first
second onNext
second

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=135746&siteId=1