Use reified type parameter for executeCatching; sync / async handlers

The unsafe cast before would throw an exception if any other generic
parameter than `Exception` was used without passing the class reference
explicitly.

It can now also be specified whether the exception handler is to be
executed sync or async, defaulting to sync.
This commit is contained in:
F0Xde
2020-10-18 11:16:03 +02:00
parent b72424d36d
commit 95a6eef6df
2 changed files with 54 additions and 24 deletions

View File

@@ -104,6 +104,14 @@ fun task(
}
fun runTask(sync: Boolean, runnable: () -> Unit) {
if (sync) {
sync(runnable)
} else {
async(runnable)
}
}
/**
* Starts a synchronous task.
*/