Package-level declarations

Types

Link copied to clipboard
data class ErrorWithCache<out Ok : Any, out Error : Any>(val error: Error, val cache: Ok? = null)

A utility class that can be used in tandem with Fetch to provide an error with some cached data.

Link copied to clipboard
typealias FaultyFetch<Error> = Flow<Fetch<Faulty<Error>>>

Alias for a flow that fetches a faulty result.

Link copied to clipboard
sealed interface Fetch<out T : Any>

Encapsulates a reactive asynchronous future, such as.

Link copied to clipboard
typealias FetchFlow<T> = Flow<Fetch<T>>

Alias for a Flow of Fetch statuses.

Link copied to clipboard
value class Fetching<out T : Any>(val cache: T? = null) : Fetch<T>

A fetch operation that is currently in progress.

Link copied to clipboard
value class Finished<out T : Any>(val result: T) : Fetch<T>

A fetch operation that has finished.

Link copied to clipboard
typealias MaybeFetch<Ok> = Flow<Fetch<Maybe<Ok>>>

Alias for a flow that fetches a maybe result.

Link copied to clipboard
typealias OutcomeFetch<Ok, Error> = Flow<Fetch<Outcome<Ok, Error>>>

Alias for a flow that fetches an outcome result.

Link copied to clipboard
data object Prefetch : Fetch<Nothing>

A fetch operation that has not yet been started.

Link copied to clipboard
typealias ResultFetch<Ok> = Flow<Fetch<KotlinResult<Ok>>>

Alias for a flow that fetches a result.

Link copied to clipboard
class SafeFetchFlow<T : Any> : AbstractFlow<Fetch<T>> , Flow<Fetch<T>>

AbstractFlow implementation for FetchFlow.

Functions

Link copied to clipboard
inline suspend fun <T> FlowCollector<T>.emit(recover: FlowCollector<T>.(Throwable) -> T = { throw it }, block: FlowCollector<T>.() -> T)

Emit the result of block, with a built-in try-catch.

Link copied to clipboard
fun <T : Any> fetch(timeout: Duration = Duration.INFINITE, recover: FetchCollector<T>.(Throwable) -> Fetch<T> = { throw it }, block: suspend FetchCollector<T>.() -> T): FetchFlow<T>

Create a new FetchFlow with the given block of code to execute.

Link copied to clipboard
inline suspend fun <T : Any> FetchCollector<T>.fetching(cache: T? = null)

Send a fetch in progress status to the current flow-scope.

Link copied to clipboard
inline suspend fun <T : Any> FetchCollector<T>.finished(result: T)

Send a fetch finished status to the current flow-scope, with the encapsulated result.

Link copied to clipboard

Transforms the encapsulated error and cache.

Link copied to clipboard

Transforms the encapsulated cache.

Link copied to clipboard

Transforms the encapsulated error.

Link copied to clipboard
inline suspend fun FetchCollector<Nothing>.prefetch()

Send a fetch not started status to the current flow-scope.