Linked Questions
39 questions linked to/from How do I synchronously return a value calculated in an asynchronous Future?
0 votes
1 answer
3k views
reqwest example POST request not compiling [duplicate]
I tried to complied the following reqwest example: let client = reqwest::Client::new(); let res = client.post("http://httpbin.org/post") .body("the exact body that is sent") ...
2 votes
1 answer
4k views
How to await a Rust Future on a non-async function [duplicate]
Rust newbie here (<7 days into learning), the second hurdle I am trying to overcome after ownership rule is async/await. I am writing a test that calls an async function and I need to get the ...
2 votes
1 answer
2k views
How do I call an async function in a match statement under a non-async main function in Rust? [duplicate]
I have a program that does various simple things based on user selection. fn main() { let mut user_input = String::new(); // Initialize variable to store user input println!("Select an ...
1 vote
0 answers
1k views
Calling an async function synchronously with tokio [duplicate]
I have been scouring the docs to find a way to call an asynchronous function synchronously. Specifically, I am trying to call tokio::sync::mutex::lock from a Display implementation to provide useful ...
0 votes
1 answer
834 views
Return error from async function to caller of synchronous function [duplicate]
I am learning Tokio/futures and can't find a way to return the error up to the caller in the main function; is this possible? My use case is for AWS Lambda with the runtime being synchronous and ...
-1 votes
1 answer
371 views
Rust reqwest call on match branches [duplicate]
I would like to call two functions that perform an HTTP call with reqwest on two different branches of a match: async fn list_projects() -> Result<(), reqwest::Error> { let body = ...
95 votes
3 answers
132k views
How to iterate through a Hashmap, print the key/value and remove the value in Rust?
This should be a trivial task in any language. This isn't working in Rust. use std::collections::HashMap; fn do_it(map: &mut HashMap<String, String>) { for (key, value) in map { ...
69 votes
2 answers
43k views
How can I perform parallel asynchronous HTTP GET requests with reqwest?
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 each ...
39 votes
5 answers
26k views
How do I read the output of a child process without blocking in Rust?
I'm making a small ncurses application in Rust that needs to communicate with a child process. I already have a prototype written in Common Lisp. I'm trying to rewrite it because CL uses a huge amount ...
23 votes
2 answers
28k views
How to run an asynchronous task from a non-main thread in Tokio?
use std::thread; use tokio::task; // 0.3.4 #[tokio::main] async fn main() { thread::spawn(|| { task::spawn(async { println!("123"); }); }) .join(); } ...
19 votes
1 answer
16k views
Calling async function inside an iterator
I want to await an async function inside a closure used in an iterator. The function requiring the closure is called inside a struct implementation. I can't figure out how to do this. This code ...
11 votes
1 answer
16k views
What is the smallest feature set to enable polling a future with Tokio?
I want to poll an async function: #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { some_function().await; } I am currently activating all features: tokio =...
17 votes
1 answer
19k views
Why does Tokio return the error "Cannot drop a runtime in a context where blocking is not allowed"?
I have a Tokio client that talks to a remote server and is supposed to keep the connection alive permanently. I've implemented the initial authentication handshake and found that when my test ...
5 votes
2 answers
7k views
How to asynchronously explore a directory and its sub-directories?
I need to explore a directory and all its sub-directories. I can explore the directory easily with recursion in a synchronous way: use failure::Error; use std::fs; use std::path::Path; fn main() -&...
12 votes
2 answers
9k views
How do I implement an async Drop in Rust?
I have an async fn that returns a type, and want to implement Drop on that type that calls another async function. It's not clear how to do this, and I can't find anything in the docs. The most ...