Skip to content

Commit 4a7c14f

Browse files
committed
clean up execution logic a bit
1 parent 98b7af5 commit 4a7c14f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/main/java/de/sldk/mc/metrics/Metric.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,27 @@ protected Plugin getPlugin() {
2828
}
2929

3030
public CompletableFuture<Void> collect() {
31+
return CompletableFuture.runAsync(() -> {
32+
if (!enabled) {
33+
return;
34+
}
3135

32-
if (!enabled) {
33-
return CompletableFuture.completedFuture(null);
34-
}
36+
/* If metric is capable of async execution run it on a thread pool */
37+
if (isAsyncCapable()) {
3538

36-
if (isAsyncCapable()) {
37-
/* If metric is capable of async execution, do it */
38-
return CompletableFuture.runAsync(() -> {
3939
try {
4040
doCollect();
4141
}
4242
catch (Exception e) {
4343
logException(e);
4444
}
45-
});
46-
}
45+
return;
46+
}
4747

48-
/* Otherwise run the metric on the main thread and create a future for this */
49-
return CompletableFuture.runAsync(() -> {
48+
/*
49+
* Otherwise run the metric on the main thread and make the
50+
* thread on thread pool wait for completion
51+
*/
5052
try {
5153
Bukkit.getScheduler().callSyncMethod(plugin, () -> {
5254
try {

0 commit comments

Comments
 (0)