Answer the question
In order to leave comments, you need to log in
Why does reqwest fail when not using tokio::main?
If you use #[tokio::main] then the code works successfully:
use futures::executor::LocalPool;
use futures::task::LocalSpawnExt;
async fn test(n: i32) {
println!("Started: {}", n);
let response: String = reqwest::get("https://www.rust-lang.org")
.await
.unwrap()
.text()
.await
.unwrap();
println!("Completed: {}. Response: {}", n, &response[0..10]);
}
#[tokio::main]
async fn main() {
let mut pool = LocalPool::new();
let mut spawner = pool.spawner();
for i in 0..5 {
spawner.spawn_local(test(i)).unwrap();
}
pool.run();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question