diff --git a/core/src/main/kotlin/dev/atick/core/utils/NetworkBoundResource.kt b/core/src/main/kotlin/dev/atick/core/utils/NetworkBoundResource.kt deleted file mode 100644 index 6595773..0000000 --- a/core/src/main/kotlin/dev/atick/core/utils/NetworkBoundResource.kt +++ /dev/null @@ -1,26 +0,0 @@ -package dev.atick.core.utils - -import kotlinx.coroutines.flow.* - -inline fun networkBoundResource( - crossinline query: () -> Flow, - crossinline fetch: suspend () -> RequestType, - crossinline saveFetchedResult: suspend (RequestType) -> Unit, - crossinline shouldFetch: (ResultType) -> Boolean = { true } -) = flow { - val data = query().first() - - val flow = if (shouldFetch(data)) { - emit(Resource.Loading(data)) - try { - saveFetchedResult(fetch()) - query().map { Resource.Success(it) } - } catch (throwable: Throwable) { - query().map { Resource.Error(it, throwable) } - } - } else { - query().map { Resource.Success(it) } - } - - emitAll(flow) -} \ No newline at end of file