Spring 5 Reactive Mono - Pass Mono value to property of object and call another mono

1.5k Views Asked by At

I'm new to the whole Spring reactive webflux. My problem is pretty simple. In my addActions() I am trying to get a Mono by calling getCurrentVal(). This works fine. But I need to get the value of that and update a property (submission.stateVal). Then pass call customService.addActions() which returns Mono. Can this be done without using block()?

@Autowired
private CustomService customService;

public Mono<CustomResponse> addActions(String id, String Jwt, Submission submission) {

Mono<String> updatedStateVal = getCurrentStateVal(tpJwt, id);
// submission.setStateVal(updatedStateVal);
// return customService.addActions(id, jwt, submission);


}

private Mono<String> getCurrentVal(String tpJwt, String id) {
        return customService.findById(id, tpJwt)
                .map(r -> r.getStateVal());
}
1

There are 1 best solutions below

0
On BEST ANSWER
return getCurrentStateVal(tpJwt, id)
    .flatMap(s -> {
        submission.setStateVal(s);
        return customService.addActions(id, tpJwt, submission);
    });