From 6e4f96d4b23ca09390e8177188609e394949b7bb Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 25 Jan 2023 18:38:46 +0100 Subject: [PATCH] WIP:refactor --- .../kafka/chat/backend/domain/ChatRoom.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java index dd7321ed..be22b1cf 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java @@ -65,6 +65,18 @@ public class ChatRoom throw new InvalidUsernameException(user); Message.MessageKey key = Message.MessageKey.of(user, id); + + Mono other = 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 mono = service .getMessage(key) .handle((existing, sink) -> @@ -79,16 +91,7 @@ public class ChatRoom } }); - return mono.>switchIfEmpty(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); - } - })); + return mono.switchIfEmpty(other); } -- 2.20.1