aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/romangraef/jdacommander/SyncRestAction.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com/romangraef/jdacommander/SyncRestAction.kt')
-rw-r--r--src/main/kotlin/com/romangraef/jdacommander/SyncRestAction.kt28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/kotlin/com/romangraef/jdacommander/SyncRestAction.kt b/src/main/kotlin/com/romangraef/jdacommander/SyncRestAction.kt
new file mode 100644
index 0000000..27b0b10
--- /dev/null
+++ b/src/main/kotlin/com/romangraef/jdacommander/SyncRestAction.kt
@@ -0,0 +1,28 @@
+package com.romangraef.jdacommander
+
+import java.util.concurrent.CompletableFuture
+import java.util.function.BooleanSupplier
+import java.util.function.Consumer
+import net.dv8tion.jda.api.JDA
+import net.dv8tion.jda.api.requests.RestAction
+
+class SyncRestAction<I>(private val jda: JDA, private val value: I) : RestAction<I> {
+ override fun getJDA(): JDA = jda
+
+ override fun setCheck(checks: BooleanSupplier?): RestAction<I> {
+ // No need for last Second checks.
+ // We don't execute HTTP requests anyways.
+ return this
+ }
+
+ override fun queue(success: Consumer<in I>?, failure: Consumer<in Throwable>?) {
+ success?.accept(value)
+ }
+
+ override fun complete(shouldQueue: Boolean): I = value
+
+ override fun submit(shouldQueue: Boolean): CompletableFuture<I> =
+ CompletableFuture.supplyAsync { value }
+
+
+} \ No newline at end of file