Skip to content

Commit cbfbc36

Browse files
committed
complete() -> submit()
1 parent 2a3bd41 commit cbfbc36

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/core/java/com/mcmoddev/mmdbot/core/util/webhook/WebhookManagerImpl.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737

3838
import java.util.List;
3939
import java.util.Objects;
40+
import java.util.concurrent.CompletableFuture;
4041
import java.util.concurrent.CopyOnWriteArrayList;
42+
import java.util.concurrent.ExecutionException;
4143
import java.util.concurrent.Executors;
4244
import java.util.concurrent.ScheduledExecutorService;
4345
import java.util.function.Consumer;
@@ -50,7 +52,7 @@ public class WebhookManagerImpl implements WebhookManager {
5052

5153
static {
5254
Runtime.getRuntime().addShutdownHook(new Thread(() ->
53-
MANAGERS.forEach(WebhookManagerImpl::close), "WebhookClosure"));
55+
MANAGERS.forEach(WebhookManagerImpl::close), "WebhookClosing"));
5456
}
5557

5658
private static ScheduledExecutorService getExecutor() {
@@ -67,7 +69,7 @@ private static ScheduledExecutorService getExecutor() {
6769
@Nullable
6870
private final Consumer<Webhook> creationListener;
6971

70-
public WebhookManagerImpl(final Predicate<String> predicate, final String webhookName, final AllowedMentions allowedMentions, final Consumer<Webhook> creationListener) {
72+
public WebhookManagerImpl(final Predicate<String> predicate, final String webhookName, final AllowedMentions allowedMentions, @javax.annotation.Nullable final Consumer<Webhook> creationListener) {
7173
this.predicate = predicate;
7274
this.webhookName = webhookName;
7375
this.allowedMentions = allowedMentions;
@@ -97,20 +99,28 @@ public void sendAndCrosspost(final IWebhookContainer channel, final WebhookMessa
9799
}
98100

99101
private Webhook getOrCreateWebhook(IWebhookContainer channel) {
100-
final var alreadyExisted = Objects.requireNonNull(channel).retrieveWebhooks()
101-
.complete()
102+
final var alreadyExisted = unwrap(Objects.requireNonNull(channel).retrieveWebhooks()
103+
.submit(false))
102104
.stream()
103105
.filter(w -> predicate.test(w.getName()))
104106
.findAny();
105107
return alreadyExisted.orElseGet(() -> {
106-
final var webhook = channel.createWebhook(webhookName).complete();
108+
final var webhook = unwrap(channel.createWebhook(webhookName).submit(false));
107109
if (creationListener != null) {
108110
creationListener.accept(webhook);
109111
}
110112
return webhook;
111113
});
112114
}
113115

116+
private static <T> T unwrap(CompletableFuture<T> completableFuture) {
117+
try {
118+
return completableFuture.get();
119+
} catch (InterruptedException | ExecutionException e) {
120+
throw new RuntimeException(e);
121+
}
122+
}
123+
114124
public void close() {
115125
webhooks.forEach((id, client) -> client.close());
116126
}

0 commit comments

Comments
 (0)