What do you get by doing that inside the future machinery? Maybe fewer tasks and their call stacks, but is that a huge problem?
Also, what’s with wake and poll? https://doc.rust-lang.org/std/future/trait.Future.html:
“Futures alone are inert; they must be actively polled to make progress, meaning that each time the current task is woken up, it should actively re-poll pending futures that it still has an interest in.
The poll function is not called repeatedly in a tight loop -- instead, it should only be called when the future indicates that it is ready to make progress (by calling wake())”
So, an asynchronous task that doesn’t have an answer yet calls wake to tell some object that it has to call poll on the task, so that the asynchronous task can make more progress? Why doesn’t it just do what it was asked to do until it has an answer?
Also, if a future is inert, how can it ever detect that it is ready to make progress and call wake?
I really do not understand this design.
I guess a UML sequence diagram (https://en.mwikipedia.org/wiki/Sequence_diagram) would help me. It would show what entities exist (if Rust’s future is inert, it can’t be much more than the memory block holding the function result and a reference to the async code. If so, what’s doing the computation?) put names on them, and show what calls they make.