From deb234e4f0f9fc555016523e65e4e2c343c0cbd8 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Fri, 3 Jul 2026 10:28:21 -0600 Subject: [PATCH] Add expect/actual for WorkerThread This will later be necessary for other targets as it only exists on JVM platforms. Other targets would just define it as a base annoation that doesn't do anything, allows us to keep thread safety on JVM platforms but still be able to compile for others that don't have it. --- .../com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt | 5 ++++- .../kotlin/com/lagradost/cloudstream3/utils/Coroutines.kt | 4 +++- .../com/lagradost/cloudstream3/utils/Coroutines.jvmCommon.kt | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 library/src/jvmCommonMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.jvmCommon.kt diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt index e13bcf5ec65..4cd8eefa63b 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt @@ -1,8 +1,10 @@ package com.lagradost.cloudstream3.mvvm +import androidx.annotation.AnyThread import com.lagradost.api.Log import com.lagradost.cloudstream3.ErrorLoadingException import com.lagradost.cloudstream3.utils.AppDebug +import com.lagradost.cloudstream3.utils.WorkerThread import kotlinx.coroutines.* import java.io.InterruptedIOException import java.net.SocketTimeoutException @@ -232,8 +234,9 @@ fun throwAbleToResource( } } +@AnyThread suspend fun safeApiCall( - apiCall: suspend () -> T, + @WorkerThread apiCall: suspend () -> T, ): Resource { return withContext(Dispatchers.IO) { try { diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.kt index d15ea129c29..444709f88a8 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.kt @@ -2,7 +2,6 @@ package com.lagradost.cloudstream3.utils import androidx.annotation.AnyThread import androidx.annotation.MainThread -import androidx.annotation.WorkerThread import com.lagradost.cloudstream3.Prerelease import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.logError @@ -10,6 +9,9 @@ import kotlinx.coroutines.* @AnyThread expect fun runOnMainThreadNative(@MainThread work: (() -> Unit)) + +internal expect annotation class WorkerThread() + object Coroutines { @AnyThread fun T.main(@MainThread work: suspend ((T) -> Unit)): Job { diff --git a/library/src/jvmCommonMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.jvmCommon.kt b/library/src/jvmCommonMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.jvmCommon.kt new file mode 100644 index 00000000000..2ae886f59fa --- /dev/null +++ b/library/src/jvmCommonMain/kotlin/com/lagradost/cloudstream3/utils/Coroutines.jvmCommon.kt @@ -0,0 +1,3 @@ +package com.lagradost.cloudstream3.utils + +internal actual typealias WorkerThread = androidx.annotation.WorkerThread