kotlinx.coroutines
kotlinx.coroutines copied to clipboard
Make withTimeout throw not a CancellationException
Fixes #1374
Report of how this went:
- The IDE managed to correctly replace the deprecated
withTimeoutwith the new overload. But! It replaceswithTimeoutwith the fully-qualified path. - When replacing
TimeoutCancellationExceptionwithTimeoutException, the IDE did not suggest replacing all the instances. Tought to say whether this is good. In our case, it wouldn't be. Also, there's the possible patterncatch (e: CancellationException) { if (e is TimeoutCancellationException) X() else Y() }, which would break ifTimeoutCancellationExceptionis blindly replaced everywhere.
The manual intervention by me was minimal (see the individual commits), but it seems that only a couple of tests have failed, and those are the stacktrace recovery tests. Not immediately obvious to me what's going on there.
How about trying to find a different name for a new withTimeout implementation?
If we decide to follow a road with a new name, I suggest making it consistent with a potential replacement of withContext*.
- -- it allows to break of structured concurrency in a bit unexpected ways (e.g. we probably should've prohibited
withContext(Job())and its behaviour withCopyableThreadContextElementmay (not should) be reconsidered