What about wrapping the withTimeout in a try catch block? Catch the CancellationException (and call your callback from there).
r
rmyhal
03/19/2021, 12:30 PM
@streetsofboston tried this already. But the operation(network call) inside
withTimeout
is getting cancelled when timeout passes and I lose my results
u
ursus
03/19/2021, 12:35 PM
sounds like you want multiple emits, ie. Flow
ursus
03/19/2021, 12:36 PM
merge(yourAction, timer(x))
c
christophsturm
03/19/2021, 12:36 PM
what about
launch { delay(500); callTimer()}
r
rmyhal
03/19/2021, 2:02 PM
Tried something like this:
Copy code
launch {
val job = launch {
// doing some long operation
}.apply { start() }
delay(N)
if (!job.isCompleted) {
// operation took longer than N millis.
}
}