3 ms·
How you do multiple async http requests in rust? Last time I checked the only way do it was using tokio crate. But tokio is a huge mess and looked like Rust++.
by slezyr 9y ago
How you do multiple async http requests in rust? Last time I checked the only way do it was using tokio crate. But tokio is a huge mess and looked like Rust++. I.e. some language based on rust.
- steveklabnik 9y agoYou're being downvoted because this is quite offtopic for this thread; I suggest you post to https://users.rust-lang.org/ https://users.rust-lang.org/ for these kinds of questions.
- ekidd 9y agoThere's a ton of work being done at the compiler level to make Tokio more pleasant. This includes: 1. async/await. This is analogous to async/await in C# and ES6, and should make the syntax a lot nicer. https://github.com/alexcrichton/futures-await https://github.com/alexcrichton/futures-await 2. Coroutines. This is the supporting technology for async/await. https://github.com/rust-lang/rfcs/blob/master/text/2033-experimental-coroutines.md https://github.com/rust-lang/rfcs/blob/master/text/2033-expe... 3. 'impl Trait'. This provides a way to say, "Look, my return type implements 'Trait', but the actual type declaration is way to tedious to write out, and anyway, it's private. This will help a lot with cleaning up complex Tokio types. https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md https://github.com/rust-lang/rfcs/blob/master/text/1522-cons... At work, we use Rust, but we're avoiding using Tokio until these features land.
- kibwen 9y agoI suspect you're being downvoted for being off-topic, consider asking on reddit.com/r/rust or StackOverflow.
- slezyr 9y agoI want response from Firefox/Servo devs. They need async http requests and they have experience in using those.
- kibwen 9y agoI don't believe that Firefox's http code is using Rust at all, and Servo's http code is notoriously neglected due to prioritizing development on the layout engine and style engine. At the moment I expect they're in the same boat as ekidd, waiting for the async/await experiments to yield fruit.
- slezyr 9y ago> Servo's http code is notoriously neglected due to prioritizing development Is it? It's freaking hard to make http code in rust at all. I just checked it's source and they use some old hyper's methods inside, which aren't available in recent versions. So you can use it only with tokio. Tokio is nightmare who those, who tries to learn rust. And I can't find a way around it. > At the moment I expect they're in the same boat as ekidd, waiting for the async/await experiments to yield fruit. I think that almost all rust users/devs there right now.
- tomjakubowski 9y agoIf you just want to do an occasional one-off async http request, then tokio is probably overkill, at least until async/await end up in the language. The simple way is: spawn a background thread, make a channel, pass the write end to the background thread, issue the http request synchronously using whatever crate you want on the background thread, write the result back over the channel, and exit the background thread. In the main thread, poll the read end of that channel from your event loop. Rust decided not to ship with a scheduler/runtime built in like Go and Node.JS have. This makes you do a little more work for this kind of thing, in exchange for finer control than a language with a runtime can provide.
- metajack 9y agoWe use hyper and rolled our own async support I believe, since it didn't exist at the time, but it is quite neglected and the general plan has been to move to futures and tokio. Firefox's network stack is called necko, and has been async for a long time I believe.
- 9y ago