mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
fix of build
This commit is contained in:
parent
e661185534
commit
90247667d1
@ -3,7 +3,7 @@ package dev.inmo.micro_utils.coroutines
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
fun <T> launchInCurrentThread(block: suspend CoroutineScope.() -> T): T {
|
||||
fun <T> launchInCurrentThread(block: suspend () -> T): T {
|
||||
val scope = CoroutineScope(Dispatchers.Unconfined)
|
||||
return scope.launchSynchronously(block)
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ package dev.inmo.micro_utils.coroutines
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T {
|
||||
fun <T> CoroutineScope.launchSynchronously(block: suspend () -> T): T {
|
||||
var result: Result<T>? = null
|
||||
val objectToSynchronize = Object()
|
||||
synchronized(objectToSynchronize) {
|
||||
launch(start = CoroutineStart.UNDISPATCHED) {
|
||||
result = safelyWithResult(block)
|
||||
result = runCatchingSafely(block)
|
||||
}.invokeOnCompletion {
|
||||
synchronized(objectToSynchronize) {
|
||||
objectToSynchronize.notifyAll()
|
||||
@ -20,7 +20,7 @@ fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T
|
||||
return result!!.getOrThrow()
|
||||
}
|
||||
|
||||
fun <T> launchSynchronously(block: suspend CoroutineScope.() -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block)
|
||||
fun <T> launchSynchronously(block: suspend () -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block)
|
||||
|
||||
fun <T> CoroutineScope.doSynchronously(block: suspend CoroutineScope.() -> T): T = launchSynchronously(block)
|
||||
fun <T> doSynchronously(block: suspend CoroutineScope.() -> T): T = launchSynchronously(block)
|
||||
fun <T> CoroutineScope.doSynchronously(block: suspend () -> T): T = launchSynchronously(block)
|
||||
fun <T> doSynchronously(block: suspend () -> T): T = launchSynchronously(block)
|
||||
|
@ -5,7 +5,9 @@ import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||
interface SafeWrapper<T> {
|
||||
fun <R> safe(block: T.() -> R): Result<R> = unsafeTarget().runCatching(block)
|
||||
fun <R> unsafe(block: T.() -> R): R = unsafeTarget().block()
|
||||
suspend fun <R> safeS(block: suspend T.() -> R): Result<R> = unsafeTarget().runCatchingSafely(block = block)
|
||||
suspend fun <R> safeS(block: suspend T.() -> R): Result<R> = unsafeTarget().run {
|
||||
runCatchingSafely(block = { block() })
|
||||
}
|
||||
suspend fun <R> unsafeS(block: suspend T.() -> R): R = unsafeTarget().block()
|
||||
fun unsafeTarget(): T
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user