std::promise and std::future work as asynchronous handshake contract on an object. Whenever the acquired object value is obtained by promise, it sets the value and passes the result between threads. Future returns the retrieved value. Since this is an asynchronous operation, future is halted till a value is provided either certain amount of time or till it gets the result.
void Customer::get_total_loan (std::promise<int> &&promise, int key)
{
std::string name = customerMap.find(key) ->second;
auto totalLoan = Customer::read_from_file (name);
std::this_thread::sleep_for(std::chrono:: seconds(5));
promise.set_value(totalLoan);
}
int main() {
std::promise<int> promise;
std::future<int> future = promise.get_future();
std::thread th(get_total_loan, std::move (promise), 12);
future.wait();
std::cout<<"Total loan of the customer: "<<future.get();
th.join();
}