William Kh
William Kh

Reputation: 30

Get the return value of a parameter of async function

I want to get return value of the function wait_for_user_input before if condition!

int wait_for_user_input(){
    // get input user
    // return input user
}
const auto future = std::async( std::launch::async, wait_for_user_input);
while( future.wait_for( std::chrono::milliseconds(200) ) == std::future_status::timeout ){
    // do somthing
}
if ("return of wait_for_user_input"="x"){
    // do somthing
}

Upvotes: 0

Views: 169

Answers (1)

N. Prone
N. Prone

Reputation: 180

When using async, you need to call future::get() on your future.

Upvotes: 3

Related Questions