Live data from Hacker News

Tokio 1.0 – async runtime for Rust

tokio.rs

21–30 of 422 posts

Re: Tokio 1.0 – async runtime for Rust

#21

Earlier quoted context omitted.

Would it be fair to compare this to Apple's Grand Central Dispatch a.k.a. libdispatch?

To me it's kind of like the event loop of node.js (which I believe comes from libuv)?

Yes, Deno uses it as its internal event loop for JS code.

Re: Tokio 1.0 – async runtime for Rust

#22

Earlier quoted context omitted.

The Rust language provides the async/await syntax, which can turn imperative code into Future objects, but to run those Future objects, you must repeatedly call their poll method. Tokio is the piece of code that calls that method. It does so in a manner such that futures are only polled if able to continue work, and not e.g. waiting for a timer. Besides that it provides lots of utilities for working with async code.

Would it be fair to compare this to Apple's Grand Central Dispatch a.k.a. libdispatch?

It's similar. libdispatch is primarily a task queue to simplify and optimize multithreaded workloads in objc/swift. Tokio uses a similar task queue pattern for scheduling cpu-bound or blocking io, but the main feature is an non-blocking/asynchronous IO runtime. Overall, it's more similar to libuv (the async io library that powers node.js), but with built-in support for Rust's async/await syntax

Re: Tokio 1.0 – async runtime for Rust

#23
post #8

Can someone explain to a non-rustacean what Tokio introduces that's not part of Rust? It looks like Rust provides the async/await semantics, so I'm guessing this is an event loop and dispatching system?

> rustafarian

The community prefers the term "rustacean" to be as inclusive as possible. Please keep that in mind in the future.

Re: Tokio 1.0 – async runtime for Rust

#24
post #16
post #6

Congrats! I've fallen off Rust due to pivoting at work plus trying other languages but I'm intrigued again by Tokio's announcement. I'll be trying out your tutorial soon!

what did you pivot to and why, if you don't mind me asking?

Your comment was "dead", but I see nothing wrong with it and vouched for it. This is a valid question asked earnestly.

I'd honestly like to know too.

Re: Tokio 1.0 – async runtime for Rust

#25
post #9

Earlier quoted context omitted.

Replying to myself, I found this bit in the docs explaining how Tokio decorates the 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.

To provide some more color on why this isn't built in, different runtimes provide different kinds of guarantees and performance profiles. A webapp has very different requirements than an embedded system, and so we don't want to provide a single runtime. The language contains the basic things needed for the ecosystem to exist, and interoperation points, and then leaves the rest to said ecosystem. (Some of those intero…

As always, very elegant. Thanks for the added info.

Re: Tokio 1.0 – async runtime for Rust

#27
post #8

Can someone explain to a non-rustacean what Tokio introduces that's not part of Rust? It looks like Rust provides the async/await semantics, so I'm guessing this is an event loop and dispatching system?

> rustafarian The community prefers the term "rustacean" to be as inclusive as possible. Please keep that in mind in the future.

TIL, thanks for the correction

Re: Tokio 1.0 – async runtime for Rust

#28
post #25

Earlier quoted context omitted.

To provide some more color on why this isn't built in, different runtimes provide different kinds of guarantees and performance profiles. A webapp has very different requirements than an embedded system, and so we don't want to provide a single runtime. The language contains the basic things needed for the ecosystem to exist, and interoperation points, and then leaves the rest to said ecosystem. (Some of those intero…

As always, very elegant. Thanks for the added info.

You're welcome, thanks :)

If you want to dig deeper:

* https://www.infoq.com/presentations/rust-2019/

* https://www.infoq.com/presentations/rust-async-await/

Re: Tokio 1.0 – async runtime for Rust

#30
post #9

Earlier quoted context omitted.

Replying to myself, I found this bit in the docs explaining how Tokio decorates the 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.

To provide some more color on why this isn't built in, different runtimes provide different kinds of guarantees and performance profiles. A webapp has very different requirements than an embedded system, and so we don't want to provide a single runtime. The language contains the basic things needed for the ecosystem to exist, and interoperation points, and then leaves the rest to said ecosystem. (Some of those intero…

When learning Rust a few months ago, I built a small client library for a REST API using reqwest (which uses Tokio). I then started writing a web app using Tide (https://github.com/http-rs/tide). I eventually realized that it would be difficult to use the library I had built earlier since Tide uses the async-std runtime rather than Tokio. That was very disappointing. Is there any plan to make it easier to write "runtime agnostic" libraries in the future?
Post reply on HN