#include "Future.hh" #include #include #include using namespace std; using namespace bneijt; struct Number { int val; Number(int v) : val(v) {} }; boost::shared_ptr something() { size_t i = 10; while(--i) { cout << "Future thread working\n"; sleep(1); } boost::shared_ptr n(new Number(9)); return n; } int main() { //Test the future boost::function0< boost::shared_ptr > z(something); cout << "Creating future\n"; Future< boost::shared_ptr > f(z); //Call future (wait on result) cout << "Main waiting for 3 seconds\n"; sleep(3); cout << "Calling upon future to return\n"; //Future is being worked out now boost::shared_ptr r = f(); cout << "Future returned: " << r->val << endl; return 0; }