C++ examples for Async:promise
Retrieving Results from a Thread by Using a promise on One Thread
#include <future> #include <iostream> using namespace std; using FactorialPromise = promise< long long >; long long Factorial(unsigned int value) { return value == 1 ? 1/*from www . ja v a 2s . com*/ : value * Factorial(value - 1); } int main(int argc, char* argv[]) { using namespace chrono; FactorialPromise promise; future<long long> taskFuture{ promise.get_future() }; promise.set_value(Factorial(3)); cout << "Factorial result was " << taskFuture.get() << endl; return 0; }