I need your help. There is a reactive chain in a Spring WebFlux application that uses R2dbcRepository:
entityRepository //0
.findById(entityId) //1 Mono<Entity>
.doOnNext(e-> e.setValue("0")) //2
.flatMap(entity-> //3
entityRepository //4
.save(entity) //5 Mono<Entity>
.flatMap(this::process) //6 Mono<Result>
.flatMap(result-> { //7
entity.setValue("1"); //8
return entityRepository //9
.save(entity) //10 Mono<Entity>
.thenReturn(result); //11 Mono<Result>
}) //12
.flatMap(result-> /*REST request using WebFlux*/) //13 Mono<Body>
.flatMap(body -> { //14
entity.setValue("2"); //15
return entityRepository //16
.save(entity) //17 Mono<Entity>
.thenReturn(body); //18 Mono<Body>
}) //19
); //20 Mono<Body>
On line 3, there is an "entity" object that is modified later on lines 8 and 15 (probably in a different threads). Is this an unsafe publication of the "entity" object between different threads in reactive stream? Is this approach to writing a reactive chain incorrect?