mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-10-03 22:29:30 +00:00
13 lines
354 B
Kotlin
13 lines
354 B
Kotlin
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.withContext
|
|
import kotlinx.coroutines.withTimeout
|
|
import kotlin.time.Duration
|
|
|
|
suspend fun <T> realWithTimeout(time: Duration, block: suspend () -> T): T {
|
|
return withContext(Dispatchers.Default.limitedParallelism(1)) {
|
|
withTimeout(time) {
|
|
block()
|
|
}
|
|
}
|
|
}
|