diff --git a/gradle.properties b/gradle.properties index 53528b1c..cbe1e4ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,8 +13,8 @@ coroutinesVersion=1.4.2 # korlibs klockVersion=2.0.6 -kdsVersion=2.0.7 -kmemVersion=2.0.7 +kdsVersion=2.0.8 +kmemVersion=2.0.8 kryptoVersion=2.0.6 kloggerVersion=2.0.7 diff --git a/korio/src/commonMain/kotlin/com/soywiz/korio/async/Signal.kt b/korio/src/commonMain/kotlin/com/soywiz/korio/async/Signal.kt index b0b7c2e4..df16b541 100644 --- a/korio/src/commonMain/kotlin/com/soywiz/korio/async/Signal.kt +++ b/korio/src/commonMain/kotlin/com/soywiz/korio/async/Signal.kt @@ -39,6 +39,7 @@ abstract class BaseSignal(val onRegister: () -> Unit = {}) { } protected var iterating: Int = 0 protected inline fun iterateCallbacks(callback: (THandler) -> Unit) { + if (handlers.isEmpty()) return try { iterating++ handlers.fastIterateRemove { node -> diff --git a/korio/src/commonMain/kotlin/com/soywiz/korio/async/WaitSubscriber.kt b/korio/src/commonMain/kotlin/com/soywiz/korio/async/WaitSubscriber.kt new file mode 100644 index 00000000..00ab8bab --- /dev/null +++ b/korio/src/commonMain/kotlin/com/soywiz/korio/async/WaitSubscriber.kt @@ -0,0 +1,24 @@ +package com.soywiz.korio.async + +import com.soywiz.korio.lang.* +import kotlinx.coroutines.* +import kotlin.jvm.* + +suspend fun waitSubscriber(block: ((T) -> Unit) -> Cancellable): T { + val deferred = CompletableDeferred() + @Suppress("JoinDeclarationAndAssignment") + lateinit var cancellable: Cancellable + cancellable = block { + cancellable.cancel() + deferred.complete(it) + } + try { + return deferred.await() + } catch (e: CancellationException) { + cancellable.cancel() + throw e + } +} + +suspend fun waitSubscriberCloseable(block: ((T) -> Unit) -> Closeable): T = + waitSubscriber { block(it).cancellable() } diff --git a/korio/src/commonMain/kotlin/com/soywiz/korio/util/RedirectField.kt b/korio/src/commonMain/kotlin/com/soywiz/korio/util/RedirectField.kt index 8c2b5a31..0d959d98 100644 --- a/korio/src/commonMain/kotlin/com/soywiz/korio/util/RedirectField.kt +++ b/korio/src/commonMain/kotlin/com/soywiz/korio/util/RedirectField.kt @@ -12,7 +12,9 @@ class RedirectMutableField(val redirect: KMutableProperty0) { } // @TODO: Shouldn't be required anymore +@Deprecated("Shouldn't be required anymore") fun redirect(prop: KMutableProperty0) = RedirectMutableField(prop) +@Deprecated("Shouldn't be required anymore") fun redirect(prop: KProperty0) = RedirectField(prop) class RedirectMutableFieldGen(val redirect: () -> KMutableProperty0) { @@ -26,7 +28,9 @@ class RedirectFieldGen(val redirect: () -> KProperty0) { inline fun (() -> KProperty0).redirected() = RedirectFieldGen(this) inline fun (() -> KMutableProperty0).redirected() = RedirectMutableFieldGen(this) +@Deprecated("Shouldn't be required anymore") inline fun KMutableProperty0.redirected() = RedirectMutableField(this) +@Deprecated("Shouldn't be required anymore") inline fun KProperty0.redirected() = RedirectField(this) class TransformedField(val prop: KProperty0, val transform: (V) -> R) {