Revert "fix of build"

This reverts commit 90247667d1.
This commit is contained in:
InsanusMokrassar 2024-06-19 19:50:19 +06:00
parent 90247667d1
commit ab58478686
3 changed files with 7 additions and 9 deletions

View File

@ -3,7 +3,7 @@ package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
fun <T> launchInCurrentThread(block: suspend () -> T): T { fun <T> launchInCurrentThread(block: suspend CoroutineScope.() -> T): T {
val scope = CoroutineScope(Dispatchers.Unconfined) val scope = CoroutineScope(Dispatchers.Unconfined)
return scope.launchSynchronously(block) return scope.launchSynchronously(block)
} }

View File

@ -2,12 +2,12 @@ package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.* import kotlinx.coroutines.*
fun <T> CoroutineScope.launchSynchronously(block: suspend () -> T): T { fun <T> CoroutineScope.launchSynchronously(block: suspend CoroutineScope.() -> T): T {
var result: Result<T>? = null var result: Result<T>? = null
val objectToSynchronize = Object() val objectToSynchronize = Object()
synchronized(objectToSynchronize) { synchronized(objectToSynchronize) {
launch(start = CoroutineStart.UNDISPATCHED) { launch(start = CoroutineStart.UNDISPATCHED) {
result = runCatchingSafely(block) result = safelyWithResult(block)
}.invokeOnCompletion { }.invokeOnCompletion {
synchronized(objectToSynchronize) { synchronized(objectToSynchronize) {
objectToSynchronize.notifyAll() objectToSynchronize.notifyAll()
@ -20,7 +20,7 @@ fun <T> CoroutineScope.launchSynchronously(block: suspend () -> T): T {
return result!!.getOrThrow() return result!!.getOrThrow()
} }
fun <T> launchSynchronously(block: suspend () -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block) fun <T> launchSynchronously(block: suspend CoroutineScope.() -> T): T = CoroutineScope(Dispatchers.Default).launchSynchronously(block)
fun <T> CoroutineScope.doSynchronously(block: suspend () -> T): T = launchSynchronously(block) fun <T> CoroutineScope.doSynchronously(block: suspend CoroutineScope.() -> T): T = launchSynchronously(block)
fun <T> doSynchronously(block: suspend () -> T): T = launchSynchronously(block) fun <T> doSynchronously(block: suspend CoroutineScope.() -> T): T = launchSynchronously(block)

View File

@ -5,9 +5,7 @@ import dev.inmo.micro_utils.coroutines.runCatchingSafely
interface SafeWrapper<T> { interface SafeWrapper<T> {
fun <R> safe(block: T.() -> R): Result<R> = unsafeTarget().runCatching(block) fun <R> safe(block: T.() -> R): Result<R> = unsafeTarget().runCatching(block)
fun <R> unsafe(block: T.() -> R): R = unsafeTarget().block() fun <R> unsafe(block: T.() -> R): R = unsafeTarget().block()
suspend fun <R> safeS(block: suspend T.() -> R): Result<R> = unsafeTarget().run { suspend fun <R> safeS(block: suspend T.() -> R): Result<R> = unsafeTarget().runCatchingSafely(block = block)
runCatchingSafely(block = { block() })
}
suspend fun <R> unsafeS(block: suspend T.() -> R): R = unsafeTarget().block() suspend fun <R> unsafeS(block: suspend T.() -> R): R = unsafeTarget().block()
fun unsafeTarget(): T fun unsafeTarget(): T