diff --git a/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/event/coroutines/SuspendableEvent.kt b/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/event/coroutines/SuspendableEvent.kt index 6e474800..0925d06d 100644 --- a/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/event/coroutines/SuspendableEvent.kt +++ b/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/event/coroutines/SuspendableEvent.kt @@ -8,9 +8,9 @@ inline fun SuspendableEvent<*, *>.getAs() = when (this) { is SuspendableEvent.Failure -> error as? X } -suspend inline fun SuspendableEvent.success(crossinline f: suspend (V) -> Unit) = fold(f, {}) +suspend inline fun SuspendableEvent.success(noinline f: suspend (V) -> Unit) = fold(f, {}) -suspend inline fun SuspendableEvent<*, E>.failure(crossinline f: suspend (E) -> Unit) = fold({}, f) +suspend inline fun SuspendableEvent<*, E>.failure(noinline f: suspend (E) -> Unit) = fold({}, f) infix fun SuspendableEvent.or(fallback: V) = when (this) { is SuspendableEvent.Success -> this @@ -105,7 +105,7 @@ sealed class SuspendableEvent: ReadOnlyProperty abstract operator fun component1(): V? abstract operator fun component2(): E? - suspend inline fun fold(crossinline success: suspend (V) -> X, crossinline failure: suspend (E) -> X): X { + suspend inline fun fold(noinline success: suspend (V) -> X, noinline failure: suspend (E) -> X): X { return when (this) { is Success -> success(this.value) is Failure -> failure(this.error) @@ -164,11 +164,9 @@ sealed class SuspendableEvent: ReadOnlyProperty Failure(ex as E) } - suspend inline operator fun invoke(crossinline block: suspend () -> V): SuspendableEvent = try { - Success(block()) - } catch (ex: Throwable) { - Failure(ex) - } + suspend inline operator fun invoke( + crossinline block: suspend () -> V + ): SuspendableEvent = of(block) } } \ No newline at end of file diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/YoutubeMp3.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/YoutubeMp3.kt index 582f492a..03d0c758 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/YoutubeMp3.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/providers/YoutubeMp3.kt @@ -17,7 +17,6 @@ package com.shabinder.common.di.providers import co.touchlab.kermit.Kermit -import com.shabinder.common.di.audioToMp3.AudioToMp3 import com.shabinder.common.di.youtubeMp3.Yt1sMp3 import com.shabinder.common.models.corsApi import com.shabinder.common.models.event.coroutines.SuspendableEvent @@ -30,9 +29,9 @@ interface YoutubeMp3: Yt1sMp3 { operator fun invoke( client: HttpClient, logger: Kermit - ): AudioToMp3 { - return object : AudioToMp3 { - override val client: HttpClient = client + ): YoutubeMp3 { + return object : YoutubeMp3 { + override val httpClient: HttpClient = client override val logger: Kermit = logger } }