-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Renaming tokio::main attribute #1564
Comments
@vorner what about: #[tokio::run]
async fn main() {}
#[tokio::run]
async fn do_thing() {} |
That would probably work too. Still, it would be nice to also be able to do: #[tokio::run]
async fn run_server(port: usize) -> Result<(), Error> {
unimplemented!()
}
fn main() {
blocking_initialization();
if let Err(e) = run_server(1234) {
error!(":-( {}", e);
std::process::exit(1);
}
blocking_shutdown();
} |
I wonder if mixing Putting it on main doesn't matter too much since by default no-one calls it, but the example above gave me pause for a second. |
I wonder if it makes sense to keep async fn run_server(port: usize) -> Result<(), Error> {
unimplemented!()
}
fn main() {
blocking_initialization();
if let Err(e) = tokio::runtime::block_on(run_server(1234)) {
error!(":-( {}", e);
std::process::exit(1);
}
blocking_shutdown();
} This seems like it gets us closer to your goal while still keeping main to make getting started easier? |
To be honest, I was actually OK with creating a Runtime manually and calling Renaming the attribute, so it hints it can be applied to other things than just But maybe it's OK to just leave it as it is but have one of the well visible examples use some other mechanism than the attribute? So beginners know there's a choice and roughly in which direction to search the documentation. |
I think we could also do a better job in the docs at explaining the runtime. So maybe the improvements need to go there as well? |
I also will lift restriction on arguments for non-main functions |
If we change it, my two votes would be That said, the |
Would it also be possible to do
|
@tekjar Honestly, that code feels confusing to me. What does it block on, on the closure or on the call to thread::spawn? Logically the former, syntactically the latter. Maybe you wanted something like?: thread::spawn(#[tokio::enter(single_thread)] move {
}); (personally, I don't have opinion if this is useful) |
Yeah what ever makes sense logically && syntactically. I'm planning to return a
Instead of creating a function with On a different note, is it possible to support for loop streams with |
tl;dr now As for macro itself I believe its functionality should remain as it is, and name can be whatever people feel more fitting. We can even lift @tekjar extending this macro to something more than functions seems just complexity for no reason. |
I don't think we're going to rename the attribute and, as mentioned, it works w/ arguments now! |
A follow up on a blog post https://vorner.github.io/2019/09/15/play-with-new-async.html and a discussion in the dev channel.
The
#[tokio::main]
can actually be applied to any function that doesn't take arguments. This is non-obvious from the name (and theruntime
crate explicitly forbids such use). Would it make sense to rename it to eg.#[tokio::entry]
?Furthermore, is there a need for the „doesn't take arguments“ limitation?
Version
0.2.0-alpha.4
Platform
(but probably irrelevant here)
Subcrates
tokio-macros
The text was updated successfully, but these errors were encountered: