#3 Sefiros
Zaklad je future<T>. Reprezentuje navratovu hodnotu asynchronenej udalosti( std::async, std::packaged_task, std::promise)
Priklad:
#include <iostream>
#include <thread>
#include <chrono>
#include <future>
int main(){
std::future<std::string> x = std::async(std::launch::async, [](){
for(unsigned i = 4; i; --i){
std::cout << "x: " << i << '\n';
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
}
return std::string("x end\n");
});
std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) );
std::future<std::string> y = std::async(std::launch::async, [](){
for(unsigned i = 4; i; --i){
std::cout << "_y: " << i << '\n';
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
}
return std::string("_y end\n");
});
//get interne vola metodu wait ktora pocka az skonci thread
std::cout << x.get() << y.get();
}