Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -232,8 +234,9 @@ fun <T> throwAbleToResource(
}
}

@AnyThread
suspend fun <T> safeApiCall(
apiCall: suspend () -> T,
@WorkerThread apiCall: suspend () -> T,
): Resource<T> {
return withContext(Dispatchers.IO) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ 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
import kotlinx.coroutines.*

@AnyThread
expect fun runOnMainThreadNative(@MainThread work: (() -> Unit))

internal expect annotation class WorkerThread()

object Coroutines {
@AnyThread
fun <T> T.main(@MainThread work: suspend ((T) -> Unit)): Job {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.lagradost.cloudstream3.utils

internal actual typealias WorkerThread = androidx.annotation.WorkerThread