mirror of
https://github.com/Minestom/Minestom.git
synced 2024-06-23 21:15:01 +02:00
28 lines
855 B
Java
28 lines
855 B
Java
package net.minestom.server.utils.async;
|
|
|
|
import net.minestom.server.MinecraftServer;
|
|
import org.jetbrains.annotations.ApiStatus;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
@ApiStatus.Internal
|
|
public final class AsyncUtils {
|
|
public static final CompletableFuture<Void> VOID_FUTURE = CompletableFuture.completedFuture(null);
|
|
|
|
public static <T> CompletableFuture<T> empty() {
|
|
//noinspection unchecked
|
|
return (CompletableFuture<T>) VOID_FUTURE;
|
|
}
|
|
|
|
public static @NotNull CompletableFuture<Void> runAsync(@NotNull Runnable runnable) {
|
|
return CompletableFuture.runAsync(() -> {
|
|
try {
|
|
runnable.run();
|
|
} catch (Exception e) {
|
|
MinecraftServer.getExceptionManager().handleException(e);
|
|
}
|
|
});
|
|
}
|
|
}
|