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
This commit is contained in:
divios 2021-09-12 11:08:08 +02:00 committed by GitHub
parent 799bf30651
commit c0a2bc8cc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 <br>
*
* @param runnable task to run
*/
public CompletableFuture<Void> asyncFuture(Runnable runnable) {
return CompletableFuture.runAsync(runnable);
}
/**
* Queue a task to be run synchronously.