-
Notifications
You must be signed in to change notification settings - Fork 336
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
Simplify hello-tokio, move intro article #801
base: master
Are you sure you want to change the base?
Conversation
- Move tutorial overview page which had tokio general information but no tutorial specific info to /tokio/introduction - Move tutorial setup page to /tokio/tutorial from /tutorial/setup and add a redirect for seo-juice.
This is the MSRV of latest Tokio release. Added more up to date rust version number.
Move these parts of the article out of the hello-tokio article into their own standalone topics. This way they don't break the flow of the tutorial, and can be referenced and linked outside of that flow more easily. Rewrote some of the parts of the hello-world for clarity and to update versions. Added more internal links and conclusion section. Related to: tokio-rs#401
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.
This is a pretty small page. Perhaps we could just link directly to https://docs.rs/tokio/latest/tokio/#feature-flags without this intermediate page?
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.
I'm ok with doing that. There was a mention of adding this page in #401, so I figured it would be worth keeping.
# Async `main` function | ||
|
||
The main function used to launch the application differs from the usual one | ||
found in most of Rust's crates. | ||
|
||
1. It is an `async fn` | ||
2. It is annotated with `#[tokio::main]` | ||
|
||
An `async fn` is used as we want to enter an asynchronous context. However, | ||
asynchronous functions must be executed by a [runtime]. The runtime contains the | ||
asynchronous task scheduler, provides evented I/O, timers, etc. The runtime does | ||
not automatically start, so the main function needs to start it. | ||
|
||
[runtime]: https://docs.rs/tokio/1/tokio/runtime/index.html | ||
|
||
The `#[tokio::main]` function is a macro. It transforms the `async fn main()` | ||
into a synchronous `fn main()` that initializes a runtime instance and executes | ||
the async main function. | ||
|
||
For example, the following: | ||
|
||
```rust | ||
#[tokio::main] | ||
async fn main() { | ||
println!("hello"); | ||
} | ||
``` | ||
|
||
gets transformed into: | ||
|
||
```rust | ||
fn main() { | ||
let mut rt = tokio::runtime::Runtime::new().unwrap(); | ||
rt.block_on(async { | ||
println!("hello"); | ||
}) | ||
} | ||
``` |
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.
It would be nice to have a link to the documentation of the #[tokio::main]
macro. The link could say something along the lines of "to see all of the options you can specify when using #[tokio::main]
, see the documentation" or similar.
```rust,ignore | ||
# let result = 42; | ||
println!("got value from the server; result={result:?}"); | ||
``` |
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.
This let result = 42
line shows up in the rendered html for me. Perhaps you need to drop the ignore
from the codeblock to fix this?
Co-authored-by: Alice Ryhl <[email protected]>
I moved the intro to tokio introdcution that was at /tokio/tutorial into its own section as it contains no tutorial specific info.
The tutorial/setup page is now at /tutorial (and a redirect is added from the original page)
A bunch of content out of hello-tokio has been extracted to topics/{async,feature-flags}
Fixes: #461
Related: #401
Related: #503 (comment)