3 ms·
If 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
by tomjakubowski 9y ago
If 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.