Add timeout to network messages

This commit is contained in:
William committed 2022-08-24 22:30:00 +01:00
1 parent 98931c1900
commit d368befabd
2 files changed
+9 -7

No files matched your search

@@ -109,16 +109,16 @@ public class RequestManager {
MessagePayload.withTeleportRequest(request),
Message.RelayType.MESSAGE,
plugin.getSettings().clusterId))
.thenApply(message -> {
if (message.payload.teleportRequest == null) {
.orTimeout(3, TimeUnit.SECONDS)
.exceptionally(throwable -> null)
.thenApply(reply -> {
if (reply == null || reply.payload.teleportRequest == null) {
return false;
}
// If the message was ignored by the recipient, return false
return message.payload.teleportRequest.status == TeleportRequest.RequestStatus.PENDING;
})
.orTimeout(3, TimeUnit.SECONDS)
.exceptionally(throwable -> false).join();
return reply.payload.teleportRequest.status == TeleportRequest.RequestStatus.PENDING;
}).join();
});
}
return CompletableFuture.supplyAsync(() -> false);