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 = { Initial }) { 4 }
Fetch.Initial is used for initial states, and is not emitted by the FetchFlow.
Fetch.Fetching is emitted automatically before block is executed.
Fetch.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
Filter a FetchFlow by isFinished, and map to the result.
Convenience function to apply flatMapFetching inside a Flow.
Convenience function to apply flatMapInitial inside a Flow.
Convenience function to apply mapFetchingToFinished inside a Flow.
Convenience function to apply mapToFinished inside a Flow.
Convenience function to apply mapFetchingToFinished inside a Flow.
Perform non-mutating actions according to Fetch state on each flow emission.