Live data from Hacker News

Tokio 1.0 – async runtime for Rust

tokio.rs

91–100 of 422 posts

Re: Tokio 1.0 – async runtime for Rust

#91
post #33

Earlier quoted context omitted.

C#/.NET has all of this already. You don't have to import anything else to use async/await.

[deleted: man, was that a dumb comment]

Of course it does just because C# comes with all the bells and whistles doesn't mean you can't write your own in it. https://docs.microsoft.com/en-us/dotnet/api/system.threading...

Re: Tokio 1.0 – async runtime for Rust

#92
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?

tokio is to rust what asyncio is to Python.

And nodejs or web eventloop is to JavaScript. They provide the executor and the timeout/IO primitives.

Re: Tokio 1.0 – async runtime for Rust

#93
post #77

I don't really get these modern async APIs. In languages like Javascript I thought they only made sense because JS interpreters are (historically) single-threaded, so you really have no choice but async to express some concepts. Fine. But in Rust you can just spawn threads, share data through channels or mutexes, use OS-provided async IO primitives to poll file descriptors and do event-driven programming etc... I tri…

> when you have a huge number of very small tasks running concurrently because that's generally where OS-driven parallelism tends to suffer but is it such a common scenario

Web servers are all about I/O and handling small tasks (requests), and are a perfect use case for asynchronous programming.

> That sounds like premature optimization in many situations IMO

Maybe in some cases... but then just don't use futures. Rust does not have a runtime, so it gives you the choice. std is all blocking, so you can spawn threads and do event-driven programming, which might be just fine for a lot of people.

async is more ergonomic for Rust specific reasons, makes sense for a lot of use cases, and was a highly requested language feature, so it was added to the language. OS threads can work just fine for many people. If that includes you, you don't have to use async.

Re: Tokio 1.0 – async runtime for Rust

#94
post #77

I don't really get these modern async APIs. In languages like Javascript I thought they only made sense because JS interpreters are (historically) single-threaded, so you really have no choice but async to express some concepts. Fine. But in Rust you can just spawn threads, share data through channels or mutexes, use OS-provided async IO primitives to poll file descriptors and do event-driven programming etc... I tri…

There are some pretty bad usability problems with most async APIs too.

One is they make your functions colored; async functions world best with other async functions while normal blocking functions work best with other blocking functions.

They also introduce a lot of noise; putting async/await everywhere doesn't tell you anything interesting.

Considering a normal-sized Linux server can handle a million threads without much trouble, it really seems like misplaced effort.

Re: Tokio 1.0 – async runtime for Rust

#95
post #77

I don't really get these modern async APIs. In languages like Javascript I thought they only made sense because JS interpreters are (historically) single-threaded, so you really have no choice but async to express some concepts. Fine. But in Rust you can just spawn threads, share data through channels or mutexes, use OS-provided async IO primitives to poll file descriptors and do event-driven programming etc... I tri…

Async/await matters in Rust specifically because the borrow checker makes writing code without it difficult, inefficient, and unergonomic: http://aturon.github.io/tech/2018/04/24/async-borrowing/ (note that some of the details have changed here, but the thrust of it is very much the same.) That said, if you can get your job done without this stuff, that's fine too, but the reasons it was pursued specifically involve…

It all comes down to "is it such a common scenario?". Honest answer is no. async is for specialized situations and shouldn't be the default.

Re: Tokio 1.0 – async runtime for Rust

#96
post #77

I don't really get these modern async APIs. In languages like Javascript I thought they only made sense because JS interpreters are (historically) single-threaded, so you really have no choice but async to express some concepts. Fine. But in Rust you can just spawn threads, share data through channels or mutexes, use OS-provided async IO primitives to poll file descriptors and do event-driven programming etc... I tri…

It's syntactic sugar that makes code a lot easier to reason about.

Synchronous code is even easier to reason about than code using async syntax sugar.

Re: Tokio 1.0 – async runtime for Rust

#97
post #95

Earlier quoted context omitted.

Async/await matters in Rust specifically because the borrow checker makes writing code without it difficult, inefficient, and unergonomic: http://aturon.github.io/tech/2018/04/24/async-borrowing/ (note that some of the details have changed here, but the thrust of it is very much the same.) That said, if you can get your job done without this stuff, that's fine too, but the reasons it was pursued specifically involve…

It all comes down to "is it such a common scenario?". Honest answer is no. async is for specialized situations and shouldn't be the default.

Depending on the kind of work you're doing, it may or may not be. If you're doing a lot of network IO, then yes, it is very common.

Re: Tokio 1.0 – async runtime for Rust

#98
post #79

Earlier quoted context omitted.

If core rust provides an interface for async/await why does usage of it tie you to a specific runtime? Whats the point of that?

Usage of it, on its own, does not tie you to a specific runtime. Using runtime-specific features and APIs ties you to a specific runtime.

Is this just an artifact of the current work in progress state of things? Is it just a matter of the interface settling and library authors providing a bit more configuration options to become runtime agnostic?
Post reply on HN