Notification texts go here Contact Us Buy Now!

Mono<Void>.flatMap is not getting invoked when it returns Mono<Something>

Mono<Void>.flatMap is not getting invoked when it returns Mono<Something>

Mono<Void> doesn't produce a value because Void is not an object. Basically, it's the same as an empty Mono; it just completes without any actual element.

As per docs: https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html

Mono<Void> should be used for Publisher that just completes without any value.

So a flatMap, as well as any other method that is supposed to process a value, would never be called after Mono.just(music).then().flatMap.

But if you just want to update and return the value you already have, then you can do:

return filePart.transferTo(file).then(Mono.defer({
    music.setFilePath(file.getAbsolutePath());
    music.setMeta(new Metadata());
    log.info(String.valueOf(music));
    // assuming .save returns a publisher
    return this.musicRepository.save(music);
});
  

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.