rust-tokio Questions
3
It seems one cannot use #[tokio-test] for test async functions in the Rust doc test?
For now I have to write an async main function and tag it with #[tokio-main] and call test_fn().await in it to l...
Loquat asked 28/10, 2020 at 7:41
1
Solved
I have some async function
async fn get_player(name: String, i: Instant) -> Option<Player> {
// some code here that returns a player structs
}
in my main function i want to run the above ...
Along asked 20/7, 2022 at 16:25
1
Solved
I know that Axum is built on top of Tokio and Tokio has a multi-threaded scheduler and current-threaded scheduler.
Is it possible to set the runtime to make it serve the requests in single thread?
...
Kierstenkieselguhr asked 15/7, 2022 at 3:38
1
I am making a web server capable of async operation using tokio.
I created a task via tokio::spawn, and I saw tokio::task::spawn working as well.
What is the difference between tokio::sapwn and tok...
Normie asked 19/6, 2022 at 8:18
2
Solved
I want to implement a futures::Stream for reading and parsing the standard output of a child subprocess.
What I'm doing at the moment:
spawn subprocess and obtain its stdout via std::process met...
Pleinair asked 12/3, 2018 at 23:20
2
Solved
I want to write some generic retry logic for a future.
I know the concrete return type and want to retry the same future.
My code only has access to the future - I do not want to wrap every fn call...
Obstetrician asked 19/10, 2021 at 17:21
1
I'm experimenting with how to stop asynchronous TCP connections and packet reading using Rust's tokio. I’ve written a way to stop the loop on CTRL+C or timeout event using channel and select, but a...
Omar asked 18/3, 2022 at 9:9
3
I'm writing a service with warp in Rust. When the service receives a SIGTERM signal, I'd like to have it shutdown gracefully and possibly do some logging or other work.
I have tried a number of exa...
Bridgeport asked 24/2, 2022 at 22:20
2
Solved
I'm having trouble understanding how to write concurrent async code encapsulated in one single structure.
I'm not sure how to explain the problem exactly, so i'll try to do it with an example.
Let'...
Antherozoid asked 13/11, 2021 at 14:46
2
Solved
I have a Vec of futures which I want to execute concurrently (but not necessarily in parallel). Basically, I'm looking for some kind of select function that is similar to tokio::select! but takes a...
Rossiter asked 19/1, 2022 at 16:56
2
Solved
I'm using Tokio and I want to receive requests from two different mpsc queues. select! seems like the way to go, but I'm not sure what the difference is between futures::select! and tokio::select!....
Scalar asked 23/3, 2020 at 10:22
1
Solved
I have an AsyncRead and want to convert it to a Stream<Item = tokio::io::Result<Bytes>> with tokio 0.2 and futures 0.3.
The best I've been able to do is something like:
use bytes::Byt...
Frenchy asked 13/12, 2019 at 8:6
2
Solved
The async example is useful, but being new to Rust and Tokio, I am struggling to work out how to do N requests at once, using URLs from a vector, and creating an iterator of the response HTML for e...
Janessa asked 26/6, 2018 at 13:46
3
Solved
Let's say I want to download two web pages concurrently with Tokio...
Either I could implement this with tokio::spawn():
async fn v1() {
let t1 = tokio::spawn(reqwest::get("https://example.co...
Countrywoman asked 19/10, 2021 at 23:36
1
Solved
I think my question relates to Rust Issue 57017.
The following code does not compile and produces error: future cannot be sent between threads safely due to future created by async block is not 'Se...
Guess asked 30/9, 2021 at 11:54
2
Solved
I have a main function, where I create a Tokio runtime and run two futures on it.
use tokio;
fn main() {
let mut runtime = tokio::runtime::Runtime::new().unwrap();
runtime.spawn(MyMegaFutureNu...
Tailwind asked 24/11, 2018 at 13:43
1
Solved
What's the idiomatic way to get a tokio runtime handle based on the current running environment?
For methods already run in tokio runtime, I want to use Handle.try_current().unwrap() to get the cu...
Eurydice asked 18/8, 2021 at 9:45
2
Solved
I don't know what to do next. It looks like I misunderstand something, or maybe I have not learned some critical topic.
use std::sync::Arc;
use reqwest::{Error, Response}; // 0.11.4
use tokio::syn...
Amigo asked 27/7, 2021 at 14:59
3
Solved
I have a simple TCP echo server using standard library:
use std::net::TcpListener;
fn main() {
let listener = TcpListener::bind("localhost:4321").unwrap();
loop {
let (conn, _addr) = ...
Belovo asked 4/8, 2020 at 8:54
2
Solved
How do I set a timeout for HTTP request using asynchronous Hyper (>= 0.11)?
Here is the example of the code without timeout:
extern crate hyper;
extern crate tokio_core;
extern crate futures;
us...
Myra asked 25/7, 2017 at 20:40
1
Solved
I'm experimenting with tokio's tokio::spawn and tokio::task::spawn and turns out I don't understand how the latter behaves.
When I run the following code:
#[tokio::main]
pub async fn main() {
// I...
Antrim asked 15/6, 2021 at 15:41
1
Solved
I upgraded wrap and tokio in my rust project and after the upgrade, the forward method got an error. I searched through the documentation but there was no forward method in the new version of tokio...
Pueblo asked 19/5, 2021 at 11:23
2
Solved
I'm not sure if tokio is similar to the event loop in Javascript, also a non-blocking runtime, or if it can be used to work in a similar way. In my understanding, tokio is an runtime for futures in...
Pliny asked 15/5, 2021 at 17:36
2
Solved
I want to leverage Tokio's runtime to handle a variable amount of async futures. Since the count of futures is unknown at compile time, it seems FuturesUnordered is my best option (macros such as s...
Ruder asked 1/5, 2021 at 8:37
1
Solved
I have an async function that I need to test. This function uses a mongodb::Database object to run, so I initialize the connection in the setup() function and use tokio_test::block_on() to wrap the...
Precocious asked 16/4, 2021 at 22:55
© 2022 - 2025 — McMap. All rights reserved.