Safe Fetch Flow
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 = { Prefetch }) { 4 }
Prefetch is used for initial states, and is not emitted by the FetchFlow.
Fetching is emitted automatically before block is executed.
Finished automatically encapsulates the result of block.
Return
Parameters
The duration to wait withTimeout for the fetch block to complete once.
The block of code to execute.
See also
Functions
Returns a flow containing the output of applying KotlinResult.andThen to each value of the original flow.
Returns a flow containing the Out of applying KotlinResult.andIf to each value of the original flow.
Returns a flow containing only failed values of the original flow.
Filter a FetchFlow by isNotEmpty, and unwrap the value if it exists.
TODO: Needs work / doc-comments / testing
TODO: Needs work / doc-comments / testing
Returns a flow containing only successful values of the original flow.
Map a fetch flow to flatten each emission.
Returns a flow that KotlinResult.flatten a nested KotlinResult for each value of the original flow.
TODO: Needs work / doc-comments / testing
Returns a flow containing the output of applying KotlinResult.mapFailure to each value of the original flow.
TODO: Needs work / doc-comments / testing
Returns a flow containing the output of applying KotlinResult.map to each value of the original flow.
Map a fetch flow to faulty each emission.
Map a fetch flow to maybe each emission.
Map a fetch flow to outcome each emission.
TODO: Needs work / doc-comments / testing
Returns a flow that invokes the given action if it is a failure before each value of the upstream flow is emitted downstream.
TODO: Needs work / doc-comments / testing
Returns a flow that invokes the given action if it is a success before each value of the upstream flow is emitted downstream.
Returns a flow containing the output of applying KotlinResult.tryRecover to each value of the original flow.