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