How to get the result of the future

let result = query(&client, &query_ip, &index)
                .map(|body| {
                    println!("{:?}", body);
                    let ans = real_query(&client);
                    ans
                }).map(|body| {
                    // how to get the value of Future, such as print the value of `body`
                });

beside the wait() method, how can I get the content of the Future?

Using map, you are loosing content of the future for later use (unless you are returning it later), changing the original future to other. In this specific case, you may do something like:

let result = query(&client, &query_ip, &index)
                .map(|body| {
                    println!("{:?}", body);
                    let ans = real_query(&client);
                    (body, ans)
                }).map(|(body, ans)| {
                    // how to get the value of Future, such as print the value of `body`
                    ans
                });

So the first map changes Future<BodyT, Err> to Future<(BodyT, AnsT), Err>, and the second one Future<(BodyT, AnsT), Err> to Future<AnsT, Err>. However I don't understand, why you want print the value in this place? To be exact it nevermore exist after the first map finishes, so there is nothing to print.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.