i want konw r2dbc principle, so i debug the code, but i find it work weird.
Flux.range(1, 10)
.flatMap(id -> repository.save(new Student(id, "lxp")))
.doOnNext(System.out::println)
.subscribe();
why it run all save
before run doOnNext?
In my understanding, it run save then doOnNext one by one.
it hard.hope someone can help me.thanks.
Answer is partially here
https://stackoverflow.com/a/57208219/182393
In addition, flatMap
is emitting events (saves) in an asynchronous way. So, you have range
of events, that are handled in flatMap
asynchronously (all at the same time) and then they go to doOnNext
, and finally to subscribe
.
Your code is not sequential (and this is why reactive programming causes madness).