In the following block which is inside a suspend function
Copy code
val job = launch {
if (slugs.isNotEmpty()) {
model.locations = withTimeout(10.seconds) {
locationsRepository.getLocations(slugs)
}
}
}
// Do other tasks
job.join() // Wait for timeout or completed job
return@withContext model
The docs for
withTimeout
state that
Runs a given suspending block of code inside a coroutine with the specified timeout and throws a
TimeoutCancellationException
if the timeout was exceeded.
The code that is executing inside the block is cancelled on timeout and the active or next invocation of the cancellable suspending function inside the block throws a
TimeoutCancellationException
.
It is apparent from the docs that my block would be cancelled and an exception is thrown.
Would this exception crash the App or would it just cancel the job?
e
ephemient
02/13/2024, 1:45 PM
TimeoutCancellationException
is a
CancellationException
so it will bubble up and cancel the containing scope as well. but it doesn't cancel the