Changed runTask to bukkitRun

Changed the runTask method to bukkitRun and added documentation
This commit is contained in:
bluefireoly
2020-10-18 16:53:10 +02:00
parent c872a94fb2
commit dcdb817a7c
2 changed files with 9 additions and 5 deletions

View File

@@ -40,7 +40,7 @@ abstract class ChainedRunnablePart<T, R>(
)
protected fun start(data: T) {
runTask(sync) {
bukkitRun(sync) {
val result = invoke(data)
next?.start(result)
}
@@ -52,7 +52,7 @@ abstract class ChainedRunnablePart<T, R>(
exceptionSync: Boolean,
exceptionHandler: ((E) -> Unit)?,
) {
runTask(sync) {
bukkitRun(sync) {
val result = try {
invoke(data)
} catch (e: Exception) {
@@ -61,11 +61,11 @@ abstract class ChainedRunnablePart<T, R>(
if (sync == exceptionSync) {
exceptionHandler?.invoke(e as E)
} else if (exceptionHandler != null) {
runTask(exceptionSync) {
bukkitRun(exceptionSync) {
exceptionHandler.invoke(e as E)
}
}
return@runTask
return@bukkitRun
} else throw e
}
next?.startCatching(result, exceptionClass, exceptionSync, exceptionHandler)

View File

@@ -104,7 +104,11 @@ fun task(
}
fun runTask(sync: Boolean, runnable: () -> Unit) {
/**
* Executes the given [runnable] either
* sync or async (specified by the [sync] parameter).
*/
fun bukkitRun(sync: Boolean, runnable: () -> Unit) {
if (sync) {
sync(runnable)
} else {