mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-06-03 00:15:15 +00:00
16 lines
363 B
Kotlin
16 lines
363 B
Kotlin
|
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)
|
||
|
}
|
||
|
}
|
||
|
|