-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
macros: run current_thread inside LocalSet #4027
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macro'How would you like to pay for your trip?s documentation should probably mention this behavior? Otherwise, though, this LGTM!
Done. Thanks for the review! |
@hawkw Is there anything else I should do? Do I need to squash/rebase the commits? |
We squash on merge, so that's not necessary. |
I was just hoping to get another maintainer's opinion before going ahead and merging this one. :) |
One thing I wonder is that maybe it would be better to make |
As an unscientific data point: I did an informal "spot the bug" poll and no one (n=3) realized spawn_local() won't work without a LocalSet. Making the macros do the right thing automatically likely avoids much gnashing of teeth. Maybe |
The |
It is worth adding that even with the |
7 days have passed. Is the jury verdict in? |
It should be possible to make this work though, no? |
We discussed this on Discord. Here's a summary:
I think we should change this to always adding a |
Discussion happened in this Discord thread (hopefully the link works) |
I'll look into making that work. For my understanding w.r.t. to point 1: is the fear that people are going to get confused by
|
Regarding point 1, the issue is that tests use the current_thread runtime by default, so they would get a |
I've been going over the code and IMO there are several ways of skinning this "implicit LocalSet" cat. Can a maintainer provide some feedback on the best way forward? My initial thinking was to:
But that's probably less efficient than it could be because now more work needs to be done, plus the context must be thread-local. |
The runtime object itself is not going to have an associated |
Make the #[tokio::main] and #[tokio::test] macros run the function body in a LocalSet so that tokio::task::spawn_local() just works. It's very helpful when you have hundreds of tests and don't want to repeat the same LocalSet::new().run_until(...) stanza every time.
I suppose I got confused by the discussion above but restricting it to just the macros certainly makes it easier to implement. PR updated, PTAL. |
Ping - please review? |
I'll put it on my todolist, but I'm too tired to review anything today. |
Friendly ping. |
This is being reverted in #4142. |
Make the "current_thread" flavor run the function body in a LocalSet so
that tokio::task::spawn_local() just works.
It's very helpful when you have hundreds of tests and don't want to
repeat the same LocalSet::new().run_until(...) stanza every time.
Aside: I ran the
rustfmt --check --edition 2018 $(find . -name '*.rs' -print)
command suggested in CONTRIBUTING.md but it spits out a lot of suggestions unrelated to my change. That's withrustfmt 1.4.37-stable (a178d03 2021-07-26)
.