-
Notifications
You must be signed in to change notification settings - Fork 634
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
RFC: Let's deprecate wait #571
Comments
It's sometimes useful to be able to wait for a future. I often do it during an initialisation process that can afford to take some time, and where the complexity involved in making the process properly asynchronous just isn't worth it. If the method to do this has a confusing name, let's rename it. .join()? .blockUntIlComplete()? Getting rid of this method entirely, however, is a bad move. Saying it's not needed because it's easy to reimplement (thousands of times, in every codebase that needs it) seems silly. I worry i might have misunderstood this issue; apologies if so. |
To me the main thrust of this issue is less so about the functionality and moreso about the placement of the API, in that (I'm not 100% sure where else it would go though) |
@alexcrichton In that case, i'd re-raise the idea of renaming the method to something really unattractive, rather than removing it. Failing that, how about an extension trait, so the method is not usually in scope? |
Throwing it out there, what about |
I know. However, as pointed out in my second reason,
I specifically put that point last because it's the least important.
The point is to try and protect users from shooting themselves in the leg using the API, much like Rust tries to protect users. @alexcrichton in alexcrichton/futures-await#22 (comment) you said:-
Mind sharing some of those reasons? |
While renaming the method will help to differentiate it from |
@rushmorem |
IMO the function should be removed from the |
@carllerche btw could you have a look: rust-lang/rfcs#2076 Its offtopic sorry but I couldn't reach you otherwise :) |
Not an expert but why not requiring a core in the future |
(Perhaps you meant someone else? I have no idea what this is about.) |
@SimonSapin 🤣 sorry I've meant @abonander ... edited |
Closing this in favour of tokio-rs/tokio-rfcs#2... |
I would like to see this resurrected. tokio-rs/tokio-rfcs#2 and tokio-rs/tokio-rfcs#3 seem to leave wait in place, unless I'm misunderstanding. I think it should be removed. For convenience, |
@casey tokio-rs/tokio-rfcs#3 proposes deprecating |
Oh sweet, I searched but must have missed that. Thanks! |
It's too easy to use incorrectly
I have seen a lot of people, myself included, use it incorrectly either out of ignorance or just because it's so convenient to use (sometimes both) ending up with code that block the entire thread unnecessarily. IMHO, the situation has just gotten worse with
async/await
. People who don't understand the difference betweenwait()
andawait!()
might usewait()
in theasync
macro (probably because it makes code easier to read) which will work. They will wonder why their programs are slow (it blocks the entire event loop), worse still they might not even realise this.It makes task execution confusing
According to the documentation we have 3 methods of executing futures;
wait()
, the thread pool and the event loop. I have seen some people get confused about when to use which. The documentation tries to explain this but the fact that the thread pool returns a future and that all futures have a wait method doesn't help. If we deprecatewait()
we remain with only 2, the thread pool and the event loop. However, considering that the thread pool simply returns a future, we will be forced to run that future on the event loop which brings us down to only one way to drive futures to completion.Questions that have also come up include
In my experience there is only one ideal way to drive futures to completion. That is, using an event loop. If you have tasks that are CPU bound, throw them on the thread pool and grab the CPU futures you get back. If you have tasks that are IO bound construct them as needed and grab the IO futures you get back. Multiplex your CPU futures with your IO futures as needed (you can
join
,select
them etc, all that good stuff) and grab the resulting future. Throw that resulting future on the event loop and you are done. In my experience, this is the most efficient way to use futures and deprecatingwait()
helps guide users towards this.It's easy to implement
Those who really need it can easily implement it on top of
await()
.The text was updated successfully, but these errors were encountered: