From 535f33b23a7fffc3ca4fb65388b6564e0785c996 Mon Sep 17 00:00:00 2001 From: Robinson Date: Sat, 19 Mar 2022 20:39:22 +0100 Subject: [PATCH] Removed reflection requirement --- src/dorkbox/util/CommonUtils.kt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/dorkbox/util/CommonUtils.kt b/src/dorkbox/util/CommonUtils.kt index 811568e..1b41241 100644 --- a/src/dorkbox/util/CommonUtils.kt +++ b/src/dorkbox/util/CommonUtils.kt @@ -32,18 +32,10 @@ import java.io.StringWriter import kotlin.coroutines.CoroutineContext import kotlin.coroutines.coroutineContext -inline fun T.logger(name: String): KLogger { +inline fun T.logger(name: String = T::class.java.simpleName): KLogger { return KotlinLogging.logger(name) } -inline fun T.logger(): KLogger { - if (T::class.isCompanion) { - return KotlinLogging.logger(T::class.java.enclosingClass.simpleName) - } - return KotlinLogging.logger(T::class.java.simpleName) -} - - fun Exception.stackTraceToString(): String { val exceptionWriter = StringWriter() printStackTrace(PrintWriter(exceptionWriter)) @@ -69,12 +61,19 @@ inline fun ignoreExceptions(vararg blocks: () -> Unit) { } } -fun async(dispatcher: CoroutineDispatcher = Dispatchers.IO, action: suspend CoroutineScope.() -> Unit): Job { +fun async(dispatcher: CoroutineDispatcher, action: suspend CoroutineScope.() -> Unit): Job { return GlobalScope.launch(dispatcher) { action() } } + +fun asyncIO(action: suspend CoroutineScope.() -> Unit): Job { + return GlobalScope.launch(Dispatchers.IO) { + action() + } +} + suspend fun Mutex.withReentrantLock(block: suspend () -> T): T { val key = ReentrantMutexContextKey(this)