mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-22 11:55:54 +01:00
CheckReturnValue in Scheduler
This commit is contained in:
parent
92d79d369a
commit
a4d499153d
@ -28,9 +28,9 @@ import com.discordsrv.api.discord.entity.interaction.component.ComponentIdentifi
|
||||
import com.discordsrv.api.discord.entity.interaction.component.MessageComponent;
|
||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||
import net.dv8tion.jda.api.interactions.components.ItemComponent;
|
||||
import org.jetbrains.annotations.CheckReturnValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.CheckReturnValue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -24,6 +24,7 @@ import com.discordsrv.common.scheduler.ServerScheduler;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.CheckReturnValue;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
@ -36,10 +37,12 @@ public interface IBukkitScheduler extends ServerScheduler {
|
||||
runOnMainThread(task);
|
||||
}
|
||||
|
||||
@CheckReturnValue
|
||||
default CompletableFuture<Void> executeOnMainThread(CommandSender sender, Runnable runnable) {
|
||||
return CompletableFuture.runAsync(runnable, task -> runOnMainThread(sender, task));
|
||||
}
|
||||
|
||||
@CheckReturnValue
|
||||
default <T> CompletableFuture<T> supplyOnMainThread(CommandSender sender, CheckedSupplier<T> supplier) {
|
||||
return CompletableFutureUtil.supplyAsync(supplier, task -> runOnMainThread(sender, task));
|
||||
}
|
||||
|
@ -21,10 +21,12 @@ package com.discordsrv.common.scheduler;
|
||||
import com.discordsrv.common.function.CheckedRunnable;
|
||||
import com.discordsrv.common.function.CheckedSupplier;
|
||||
import com.discordsrv.common.future.util.CompletableFutureUtil;
|
||||
import org.jetbrains.annotations.CheckReturnValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings({"UnusedReturnValue", "unused"}) // API
|
||||
public interface Scheduler {
|
||||
@ -38,24 +40,28 @@ public interface Scheduler {
|
||||
* An executor that will actually catch exceptions.
|
||||
* @return the {@link Executor}
|
||||
*/
|
||||
@CheckReturnValue
|
||||
Executor executor();
|
||||
|
||||
/**
|
||||
* Returns the {@link ExecutorService} being used.
|
||||
* @return the {@link ExecutorService}
|
||||
*/
|
||||
@CheckReturnValue
|
||||
ExecutorService executorService();
|
||||
|
||||
/**
|
||||
* Returns the {@link ScheduledExecutorService} being used.
|
||||
* @return the {@link ScheduledExecutorService}
|
||||
*/
|
||||
@CheckReturnValue
|
||||
ScheduledExecutorService scheduledExecutorService();
|
||||
|
||||
/**
|
||||
* Returns the {@link ForkJoinPool} being used.
|
||||
* @return the {@link ForkJoinPool}
|
||||
*/
|
||||
@CheckReturnValue
|
||||
ForkJoinPool forkJoinPool();
|
||||
|
||||
/**
|
||||
@ -66,12 +72,26 @@ public interface Scheduler {
|
||||
@NotNull
|
||||
Future<?> run(@NotNull Runnable task);
|
||||
|
||||
/**
|
||||
* Helper method for {@link CompletableFuture#runAsync(Runnable)}.
|
||||
*
|
||||
* @param task the task to execute
|
||||
* @return a future
|
||||
*/
|
||||
@NotNull
|
||||
@CheckReturnValue
|
||||
default CompletableFuture<Void> execute(@NotNull CheckedRunnable task) {
|
||||
return CompletableFutureUtil.runAsync(task, this::run);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for {@link CompletableFuture#supplyAsync(Supplier)}.
|
||||
*
|
||||
* @param supplier the supplier
|
||||
* @return a future
|
||||
*/
|
||||
@NotNull
|
||||
@CheckReturnValue
|
||||
default <T> CompletableFuture<T> supply(@NotNull CheckedSupplier<T> supplier) {
|
||||
return CompletableFutureUtil.supplyAsync(supplier, this::run);
|
||||
}
|
||||
@ -85,12 +105,28 @@ public interface Scheduler {
|
||||
@NotNull
|
||||
ScheduledFuture<?> runLater(@NotNull Runnable task, @NotNull Duration delay);
|
||||
|
||||
/**
|
||||
* Helper method for {@link CompletableFuture#runAsync(Runnable)} with delay.
|
||||
*
|
||||
* @param task the task to execute
|
||||
* @param delay the delay before executing the task
|
||||
* @return a future
|
||||
*/
|
||||
@NotNull
|
||||
@CheckReturnValue
|
||||
default CompletableFuture<Void> executeLater(@NotNull CheckedRunnable task, @NotNull Duration delay) {
|
||||
return CompletableFutureUtil.runAsync(task, t -> runLater(t, delay));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for {@link CompletableFuture#supplyAsync(Supplier)} with delay.
|
||||
*
|
||||
* @param supplier the supplier
|
||||
* @param delay the delay before executing the task
|
||||
* @return a future
|
||||
*/
|
||||
@NotNull
|
||||
@CheckReturnValue
|
||||
default <T> CompletableFuture<T> supplyLater(@NotNull CheckedSupplier<T> supplier, @NotNull Duration delay) {
|
||||
return CompletableFutureUtil.supplyAsync(supplier, task -> runLater(task, delay));
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ dependencyResolutionManagement {
|
||||
library('mcdependencydownload-velocity', 'dev.vankka', 'minecraftdependencydownload-velocity').versionRef('mcdependencydownload')
|
||||
|
||||
// Annotations
|
||||
library('jetbrains-annotations', 'org.jetbrains', 'annotations').version('24.0.1')
|
||||
library('jetbrains-annotations', 'org.jetbrains', 'annotations').version('24.1.0')
|
||||
library('findbugs-annotations', 'com.google.code.findbugs', 'jsr305').version('3.0.2')
|
||||
|
||||
// JDA
|
||||
|
Loading…
Reference in New Issue
Block a user