Message.MessageKey key = Message.MessageKey.of(user, id);
- Mono<Message> other = Mono.defer(() -> service
- .persistMessage(key, LocalDateTime.now(clock), text)
- .doOnNext(m ->
- {
- Sinks.EmitResult result = sink.tryEmitNext(m);
- if (result.isFailure())
- {
- log.warn("Emitting of message failed with {} for {}", result.name(), m);
- }
- }));
-
Mono<Message> mono = service
.getMessage(key)
.handle((existing, sink) ->
}
});
- return mono.switchIfEmpty(other);
+ return mono.switchIfEmpty(Mono.defer(() -> service
+ .persistMessage(key, LocalDateTime.now(clock), text)
+ .doOnNext(m ->
+ {
+ Sinks.EmitResult result = sink.tryEmitNext(m);
+ if (result.isFailure())
+ {
+ log.warn("Emitting of message failed with {} for {}", result.name(), m);
+ }
+ })));
}