Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

joshka
Copy link
Contributor

@joshka joshka commented Nov 26, 2024

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)

- 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
@joshka
Copy link
Contributor Author

joshka commented Nov 26, 2024

TOC:

image

Copy link
Contributor

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?

Copy link
Contributor Author

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.

content/tokio/topics/async.md Show resolved Hide resolved
content/tokio/tutorial/hello-tokio.md Outdated Show resolved Hide resolved
Comment on lines +97 to +134
# 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");
})
}
```
Copy link
Contributor

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.

Comment on lines +200 to 203
```rust,ignore
# let result = 42;
println!("got value from the server; result={result:?}");
```
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In hello-tokio, add note to check for .await if code seems to not run
2 participants