mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Add timeout to network messages
This commit is contained in:
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);
|
||||
|
||||
@@ -165,8 +165,10 @@ public class TeleportManager {
|
||||
MessagePayload.withPosition(position),
|
||||
Message.RelayType.MESSAGE,
|
||||
plugin.getSettings().clusterId))
|
||||
.orTimeout(3, TimeUnit.SECONDS)
|
||||
.exceptionally(throwable -> null)
|
||||
.thenApply(result -> {
|
||||
if (result.payload.teleportResult == null) {
|
||||
if (result == null || result.payload.teleportResult == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(result.payload.teleportResult);
|
||||
|
||||
Reference in new issue
Block a user