networkBoundResource

inline fun <ResultType, RequestType> networkBoundResource(crossinline query: () -> Flow<ResultType>, crossinline fetch: suspend () -> RequestType, crossinline saveFetchedResult: suspend (RequestType) -> Unit, crossinline shouldFetch: (ResultType) -> Boolean = { true }): Flow<Resource<ResultType>>

Creates a network-bound resource flow that performs a query and fetches new data if necessary.

Return

A flow emitting the resource state based on the query and fetch operations.

Parameters

ResultType

The type of the query result.

RequestType

The type of the fetched data.

query

The query function that returns a flow of the current data.

fetch

The suspend function that fetches new data.

saveFetchedResult

The suspend function that saves the fetched result.

shouldFetch

The predicate function that determines if fetching new data is necessary.