-
Notifications
You must be signed in to change notification settings - Fork 635
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
Unclear how to use CurrentThread and a "main future" #697
Comments
Similar to #698. My impression based on confusion that has been encountered is that your initial example is an anti-pattern. The primary hazard is that
So, the way I see it, there are two scenarios:
In the first case, the answer is to use So, in your case, you would process the result in an It may be that there really is a solid argument to add a way to block the thread for a single future while other tasks are also sharing the executor, unblocking when the "most important" future is ready. I would like to understand what this argument would be before trying to formalize a solution for it. |
I think discussion is effectively continuing on #699 now. |
The |
I'm closing this in favor of the executor RFC. |
A typical pattern I've seen with
tokio-core
is to do something like:The
Handle::spawn
functionality is getting folded intoCurrentThread
but unfortunately I'm not sure how to recover thelet result = core.run(srv)
functionality fromCurrentThread
. Currently the closures inCurrentThread
both return a bareR
, the value returned by the closure, and thefuture::blocking
module doesn't allow usage ofCurrentThread
. As a result, I don't think it's currently easily possible to construct a server like this, where you've got one "main future" you're interested in and it may spawn (or already have spawned) some sub-futures it was interested in.The current state of tokio-rs/tokio-rfcs#3 solves this use case with:
and the RFC's current text could be tweaked a bit to accommodate an initialization closure as well:
The text was updated successfully, but these errors were encountered: