-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Introduce migration path for long-standing issue of withTimeout #4356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
One thing that is worth tweaking around is the interaction between the new and old API. I.e. right now nothing prevents users from writing something like this:
and it seems to be quite a pattern. Probably we should mark it as |
Note to self: revisit #3716 when moving forward |
Apart from the "reuse the same name" path, one of the other options I implicitly picked here is to start with |
I think it would be better to be working towards the next breaking change opportunity where there exists two versions of each function -- Yes, this is of course not strictly necessary for Considering |
Yes, we can disrupt both On the one hand, it's indeed more sane and convenient to have them in the same package. On the other, it's an IDE alt+enter-driven matter, and it feels really off to convey a message "this function is perfectly fine, but we would like to disturb you here for the sake of (minor?) inconsistency". I find it hard to justify such a disruption (note that it is different from |
As a consumer of kotlinx-coroutines I'd like to attempt to convince you otherwise. My original comment in #1374 regarding marking the API as delicate was motivated by the lack of a proper solution. In essence, I was advocating that the maintainers should have guided people to use Since this change fixes the longstanding In contrast, the old I'd also be worried that the legacy Finally, I worry that it's pretty common for library consumers to do a blanket opt-in |
This may not be a very strong argument per say, but can't the same alt+enter argument be made for replacing In the case of replacing I don't feel super strongly one way or the other, but just something I'd raise my eyebrow at when reviewing import statements in PRs. |
Thoughts in no particular order.
|
Thanks for this issue! It's great to see progress here 😍 I really like option 3, and I second @kevincianfarini regarding the deprecation being more appropriate than marking it as delicate, for exactly the reasons described. I also believe aligning the package for
I see your point, and I agree that there are probably a bunch of materials out there warning people about |
We can't know that without considering other options. ChatGPT immediately proposed So, I wouldn't reject the idea of a new name without giving it a fair try. EDIT: |
Just a few thoughts from my POV:
All of this makes me lean towards introducing a new pair of functions, name tbd, and deprecating what we have so far. |
Just to add to the chorus -- @dkhalanskyjb and @SebastianAigner have made great points regarding preserving the old |
@dkhalanskyjb The key observation here was that IDE could do it in a less intrusive way -- instead of all Thanks for all the arguments! On a more serious note, I'll give the naming problem a go later this week |
Out of the ones mentioned so far, |
Came here to suggest |
Fair enough, we can't really know without trying.
All 3 of these IMO just feel like a convoluted way to talk about what we all know as a timeout, which was my point. Using other words to describe it is not wrong in itself, but when there is an established way to refer to something, it's more satisfying to use it. Maybe I'm overestimating how widespread the word timeout is, though, as this is just an intuition and nothing measured. I have to admit that there are actually interesting options, though, especially if we explore the name from other angles. I mean other than " I like how
I agree that I actually like Anyway, all this to say that if we do find a better name than |
A slightly different path than the discussion so far: what if the newly introduced function is called Then the existing It does make all usages slightly more verbose, but perhaps that verbosity ends up being more explicit: suffixing with |
@alexvanyo that's a fresh line of thinking, thanks!
|
Given This form is sort of inspired by the |
A summary of views we've collected across various social media posts (Twitter, Bluesky, LinkedIn): Potential names:
And, for some light hearted personal favorites: Someone also pointed out correctly that most likely, the naming for the new exception should follow a consistent naming scheme (i.e. (From these, my personal favorite remains |
Thanks for this recap @SebastianAigner ! Also, I'd like to reiterate that IMO |
Tentatively, we have a winner! |
The current state of things:
kotlinx.coroutines.withTimeout
is considered harmful -- it throws CE where it should throw TE. Enough has been written on this topic, so I won't elaborate much. Our own book,Kotlin in Action
, has a dedicated note (15.2.2
) about this gotcha, and it already should be enough. Would be nice to avoid a situation like thiskotlinx.coroutines.withTimeoutOrNull
is perfectly fine.kotlinx.coroutines.time.withTimeout
suffers from the same decease. Thetime
subpackage is an unfortunate pick indicating that the package (previously -- separate JAR) is interoperable withjava.time
entities.Additional data:
withTimeout
is twice as popular aswithTimeoutOrNull
(1 and 2)flow.timeout()
operator (luckily, under@FlowPreview
), but it is also harmful when played with coroutine-launching operators (basically, anything useable).What are our options?
Breaking behavioural change. Out of the question.
Come up with a new name.
This one comes with its own advantages and disadvantages, namely:
Pros:
withContext
if we will introduce oneCons:
withTimeoutOrNull
. Either we have semantically-similarwithTimeoutOrNull
and__withDeadline
or we sacrifice perfectly finewithTimeoutOrNull
for__withDeadlineOrNull
Reuse the same name. Originally, I had a plethora of sub-options, but the most reasonable seem to be the following:
kotlinx.coroutines.timeout.withTimeout
version (yes, the package name forwithTimeoutOrNull
andwithTimeout
will be different)@LowPriorityInOverloadResolution
on the previous version(s) ofwithTimeout
, pass it through the Beta/RC cycle. Consider marking it asDelicate
?Enum.values()
-- purely IDE-assisted replacement. Also, one more argument for KT-54106@DelicateCoroutinesApi
.====
I picked the third option, and here is the draft.
If we agree that this is the way, I'll properly follow up on the PR -- documentation, guide, tests, flow operators,
time
subpackage, as well as proper migration path in the ticket with versioning (of coroutines and IDEA).I would love to hear both @dkhalanskyjb stance on that as the maintainer and @SebastianAigner as the one who teaches people how to use coroutines.