Archived
0

Minor tweaks, switch to PostgreSQL for debuggigng purposes

This commit is contained in:
Dico Karssiens
2018-07-26 22:50:29 +01:00
parent bf1da03370
commit ea7c27a7fd
12 changed files with 135 additions and 219 deletions

View File

@@ -1,7 +0,0 @@
package io.dico.dicore.command;
public interface ICommandSuspendReceiver extends ICommandReceiver {
int getTimeout();
}

View File

@@ -0,0 +1,13 @@
package io.dico.dicore.command.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SuspensionTimeout {
// not currently implemented
int timeoutMillis();
}

View File

@@ -26,7 +26,9 @@ fun callAsCoroutine(command: ReflectiveCommand,
args: Array<Any?>): String? {
val dispatcher = Executor { task -> factory.plugin.server.scheduler.runTask(factory.plugin, task) }.asCoroutineDispatcher()
// UNDISPATCHED causes the handler to run until the first suspension point on the current thread
// UNDISPATCHED causes the handler to run until the first suspension point on the current thread,
// meaning command handlers that don't have suspension points will run completely synchronously.
// Tasks that take time to compute should suspend the coroutine and resume on another thread.
val job = async(context = dispatcher, start = UNDISPATCHED) { command.method.invokeSuspend(command.instance, args) }
if (job.isCompleted) {
@@ -48,11 +50,6 @@ fun callAsCoroutine(command: ReflectiveCommand,
private suspend fun Method.invokeSuspend(instance: Any?, args: Array<Any?>): Any? {
return suspendCoroutineOrReturn { cont ->
println()
println("Calling command method suspendedly")
println(toGenericString())
println(Arrays.toString(arrayOf(instance, *args, cont)))
println()
invoke(instance, *args, cont)
}
}