You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Flow has the timeout operator. When the timeout is reached, a TimeoutCancellationException is thrown into the Flow. Typical usage seems to be to catch the thrown exception to perform additional processing (from the .timeout kdoc):
.timeout(100.milliseconds).catch { exception ->if (exception isTimeoutCancellationException) {
// Catch the TimeoutCancellationException emitted above.// Emit desired item on timeout.
emit(-1)
} else {
// Throw other exceptions.throw exception
}
}
This is a bit unwieldy. What about having an overload for this specific case?
Declaration:
fun <T> Flow<T>.timeout(duration:Duration, block:FlowCollector<T>.() ->Unit): Flow<T>
Usage (same behavior as above):
.timeout(100.milliseconds) {
emit(-1)
}
This came up as a user of one of my libraries (Pedestal Cache), which is entirely Flow-based, attempted to represent "Get the latest value from the cache, substituting a default value if the request takes too long".
The text was updated successfully, but these errors were encountered:
Use case
Flow
has thetimeout
operator. When the timeout is reached, aTimeoutCancellationException
is thrown into theFlow
. Typical usage seems to be to catch the thrown exception to perform additional processing (from the.timeout
kdoc):This is a bit unwieldy. What about having an overload for this specific case?
Declaration:
Usage (same behavior as above):
This came up as a user of one of my libraries (Pedestal Cache), which is entirely
Flow
-based, attempted to represent "Get the latest value from the cache, substituting a default value if the request takes too long".The text was updated successfully, but these errors were encountered: