SafeFetchFlow

class SafeFetchFlow<T : Any> : AbstractFlow<Fetch<T>> , Flow<Fetch<T>>

AbstractFlow implementation for FetchFlow.

Use fetch to provide an instance of this class.

// Typealias for Flow<Fetch<Int>>
val a: FetchFlow<Int> = fetch { 4 }

// Will throw TimeoutCancellationException if [block] is not emitted within 4 seconds
val b: FetchFlow<Int> = fetch(timeout = 4.seconds) { 4 }

// The recover param can map unexpected errors to a Fetch state.
val c: FetchFlow<Int> = fetch(timeout = 4.seconds, recover = { Initial }) { 4 }

Return

FetchFlow -- a Flow that encapsulates the Fetch behaviour.

Parameters

timeout

The duration to wait withTimeout for the fetch block to complete once.

recover

The transformation to apply to any non-fatal Throwable that is caught.

block

The block of code to execute.

See also

Functions

Link copied to clipboard
inline fun <Ok : Any, Error : Any, Output> OutcomeFlow<Ok, Error>.collapse(crossinline success: suspend (Ok) -> Output, crossinline failure: suspend (Error) -> Output): Flow<Output>
Link copied to clipboard
suspend override fun collect(collector: FlowCollector<Fetch<T>>)
Link copied to clipboard
open suspend override fun collectSafely(collector: FetchCollector<T>)
Link copied to clipboard
infix fun <T : Any> FetchFlow<T>.fetchOrDefault(default: T): Flow<T>
Link copied to clipboard
inline fun <T : Any> FetchFlow<T>.fetchOrElse(crossinline recover: suspend (Fetch<T>) -> T): Flow<T>
Link copied to clipboard
fun <T : Any> FetchFlow<T>.fetchOrNull(): Flow<T?>
Link copied to clipboard
fun <T : Any> FetchFlow<T>.fetchOrThrow(): Flow<T>
Link copied to clipboard
inline fun <T> FetchFlow<T & Any>.fetchUnwrap(crossinline recover: suspend (Fetch<T & Any>) -> T = { error("Fetch has not finished!") }): Flow<T>

Attempt to unwrap a FetchFlow to produce a Flow of it's result.

Link copied to clipboard
Link copied to clipboard
fun <T : Any> FetchFlow<T>.filterOnlyFinished(): Flow<T>

Filter a FetchFlow by isFinished, and map to the result.

Link copied to clipboard
Link copied to clipboard
inline fun <T : Any> FetchFlow<T>.flatMapFetching(crossinline transform: suspend () -> Fetch<T>): FetchFlow<T>

Convenience function to apply flatMapFetching inside a Flow.

Link copied to clipboard
inline fun <In : Any, Out : Any> FetchFlow<In>.flatMapFinished(crossinline transform: suspend (result: In) -> Fetch<Out>): FetchFlow<Out>

Convenience function to apply flatMapFinished inside a Flow.

Link copied to clipboard
inline fun <T : Any> FetchFlow<T>.flatMapInitial(crossinline transform: suspend () -> Fetch<T>): FetchFlow<T>

Convenience function to apply flatMapInitial inside a Flow.

Link copied to clipboard

Convenience function to apply flatten inside a Flow.

Link copied to clipboard
inline fun <T : Any, Output> FetchFlow<T>.fold(crossinline initial: suspend () -> Output, crossinline fetching: suspend () -> Output, crossinline finished: suspend (result: T) -> Output): Flow<Output>

Fold a FetchFlow into a Flow of Output.

Link copied to clipboard
inline fun <Ok : Any, ErrorIn : Any, ErrorOut : Any> OutcomeFlow<Ok, ErrorIn>.mapEachFailure(crossinline transform: suspend (ErrorIn) -> ErrorOut): OutcomeFlow<Ok, ErrorOut>
Link copied to clipboard
inline fun <In : Any, Out : Any, Error : Any> OutcomeFlow<In, Error>.mapEachSuccess(crossinline transform: suspend (In) -> Out): OutcomeFlow<Out, Error>
Link copied to clipboard
inline fun <T : Any> FetchFlow<T>.mapFetchingToFinished(crossinline transform: suspend () -> T): FetchFlow<T>

Convenience function to apply mapFetchingToFinished inside a Flow.

Link copied to clipboard
inline fun <In : Any, Out : Any> FetchFlow<In>.mapFinished(crossinline transform: suspend (result: In) -> Out): FetchFlow<Out>

Convenience function to apply mapFinished inside a Flow.

Link copied to clipboard
inline fun <T : Any> FetchFlow<T>.mapInitialToFinished(crossinline transform: suspend () -> T): FetchFlow<T>

Convenience function to apply mapToFinished inside a Flow.

Link copied to clipboard
inline fun <In : Any, Out : Any> FetchFlow<In>.mapToFinished(crossinline initial: suspend () -> Out, crossinline fetching: suspend () -> Out, crossinline finished: suspend (result: In) -> Out): Flow<Fetch.Finished<Out>>

Convenience function to apply mapFetchingToFinished inside a Flow.

Link copied to clipboard
inline fun <Ok : Any, Error : Any> OutcomeFlow<Ok, Error>.onEachFailure(crossinline block: suspend (Error) -> Unit): OutcomeFlow<Ok, Error>
Link copied to clipboard
fun <T : Any> FetchFlow<T>.onEachFetch(initial: suspend Fetch.Initial.() -> Unit = {}, fetching: suspend Fetch.Fetching.() -> Unit = {}, fetched: suspend Fetch.Finished<T>.(T) -> Unit = {}): FetchFlow<T>

Perform non-mutating actions according to Fetch state on each flow emission.

Link copied to clipboard
inline fun <Ok : Any, Error : Any> OutcomeFlow<Ok, Error>.onEachSuccess(crossinline block: suspend (Ok) -> Unit): OutcomeFlow<Ok, Error>