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)