MicroUtils/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/DoOutsideOfCoroutine.kt

16 lines
363 B
Kotlin
Raw Normal View History

2020-09-26 16:08:39 +00:00
package dev.inmo.micro_utils.coroutines
import kotlin.coroutines.*
/**
* Call this method in case you need to do something in common thread (like reading of file in JVM)
*/
suspend fun <T> doOutsideOfCoroutine(block: () -> T): T = suspendCoroutine {
try {
it.resume(block())
} catch (e: Throwable) {
it.resumeWithException(e)
}
}