with Soft Timeout
suspend fun <T> withSoftTimeout(scope: CoroutineScope, timeoutMs: Long, onTimeout: suspend () -> T, onLateSuccess: suspend (T) -> Unit = {}, onFailure: suspend (Throwable) -> T, block: suspend () -> T): T
Executes a suspending operation with a soft timeout that doesn't cancel the underlying work.
If operation completes within timeoutMs, returns the result immediately. If timeout expires, returns onTimeout while the original work continues running on scope. When the background operation finishes, onLateSuccess is invoked for success, and onFailure for failure.
Parameters
scope
CoroutineScope for background work (must outlive current coroutine)
timeout Ms
Timeout in milliseconds
on Timeout
Fallback executed on timeout
on Late Success
Callback invoked when background operation eventually succeeds
on Failure
Callback invoked when the operation fails. Its return value is used when failure happens before the timeout.
block
The suspending operation to execute