From c0a2bc8cc5472d7023eb83591902fe61843c5793 Mon Sep 17 00:00:00 2001
From: divios <57331846+divios@users.noreply.github.com>
Date: Sun, 12 Sep 2021 11:08:08 +0200
Subject: [PATCH] Added asyncFuture
Added a method to run a task async but return a CompletableFuture. Useful if you want the task to be asynchronous but also wait for it to finish and concatenate another task or more functionalities with the CompletableFuture API
---
.../songoda/core/database/DataManagerAbstract.java | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java b/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java
index 540b68a6..caad10d0 100644
--- a/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java
+++ b/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java
@@ -12,6 +12,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
+import java.util.concurrent.CompletableFuture;
public class DataManagerAbstract {
@@ -68,6 +69,16 @@ public class DataManagerAbstract {
public void async(Runnable runnable) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, runnable);
}
+
+ /**
+ * Queue a task to be run asynchronously with all the
+ * advantages of CompletableFuture api
+ *
+ * @param runnable task to run
+ */
+ public CompletableFuture asyncFuture(Runnable runnable) {
+ return CompletableFuture.runAsync(runnable);
+ }
/**
* Queue a task to be run synchronously.