#include <iostream>
#include <string>
#include <thread>
#include <future>
void GetLineAsync(std::promise<std::string>& promise)
{
std::string input;
std::getline(std::cin, input);
promise.set_value(input);
}
int main()
{
std::promise<std::string> promise;
auto future = promise.get_future(); // future is of type 'std::future<std::string>'
std::thread tr(GetLineAsync, std::ref(promise));
while (future.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
std::cout << "Waiting for input (doing something else in the meanwhile)..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1)); // This thread job
}
tr.join();
const std::string input_c = future.get();
std::cout << "Input: " << input_c << std::endl;
}