From 9d516bb14312526e01aaf2fb5ce2c7fc549aa49f Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 25 Jan 2023 18:45:53 +0100 Subject: [PATCH] WIP:refactor --- .../kafka/chat/backend/domain/ChatRoom.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 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 878d7888..88099c04 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 @@ -66,17 +66,6 @@ public class ChatRoom Message.MessageKey key = Message.MessageKey.of(user, id); - Mono 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 mono = service .getMessage(key) .handle((existing, sink) -> @@ -91,7 +80,16 @@ public class ChatRoom } }); - 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); + } + }))); } -- 2.20.1