|
|
|
@ -147,54 +147,54 @@ cout << await_(async_ ( [] () { |
|
|
|
|
* Await all |
|
|
|
|
**/ |
|
|
|
|
|
|
|
|
|
auto a = async_ ( []() { |
|
|
|
|
cout << "A" << endl; |
|
|
|
|
return 3; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
auto b = async_ ( []() { |
|
|
|
|
cout << "B" << endl; |
|
|
|
|
throw runtime_error("Test exception"); |
|
|
|
|
return; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
auto c = async_ ( []() { |
|
|
|
|
cout << "C" << endl; |
|
|
|
|
return "Hello"; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
int a_; |
|
|
|
|
string c_; |
|
|
|
|
|
|
|
|
|
auto await_all = [&] () { |
|
|
|
|
a_ = await_(a); |
|
|
|
|
await_(b); |
|
|
|
|
c_ = await_(c); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
await_all(); |
|
|
|
|
cout << "a_ " << a_ << " c_ " << c_ << endl; |
|
|
|
|
} catch (const exception& exc) { |
|
|
|
|
cout << exc.what() << endl; |
|
|
|
|
} |
|
|
|
|
auto a = async_ ( []() { |
|
|
|
|
cout << "A" << endl; |
|
|
|
|
return 3; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// // same type |
|
|
|
|
auto b = async_ ( []() { |
|
|
|
|
cout << "B" << endl; |
|
|
|
|
throw runtime_error("Test exception"); |
|
|
|
|
return; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
vector<future<void>> fut_vec; |
|
|
|
|
for (int i=0; i<5; i++) { |
|
|
|
|
fut_vec.push_back( |
|
|
|
|
async_ ( [i]() { |
|
|
|
|
cout << "Async_ " << i << endl; |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
auto c = async_ ( []() { |
|
|
|
|
cout << "C" << endl; |
|
|
|
|
return "Hello"; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
auto await_all = [&] () { |
|
|
|
|
for (int i=0; i<fut_vec.size(); i++) { |
|
|
|
|
await_ (fut_vec[i]); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
int a_; |
|
|
|
|
string c_; |
|
|
|
|
|
|
|
|
|
auto await_all = [&] () { |
|
|
|
|
a_ = await_(a); |
|
|
|
|
await_(b); |
|
|
|
|
c_ = await_(c); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
await_all(); |
|
|
|
|
cout << "a_ " << a_ << " c_ " << c_ << endl; |
|
|
|
|
} catch (const exception& exc) { |
|
|
|
|
cout << exc.what() << endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// // same type |
|
|
|
|
|
|
|
|
|
vector<future<void>> fut_vec; |
|
|
|
|
for (int i=0; i<5; i++) { |
|
|
|
|
fut_vec.push_back( |
|
|
|
|
async_ ( [i]() { |
|
|
|
|
cout << "Async_ " << i << endl; |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto await_all = [&] () { |
|
|
|
|
for (int i=0; i<fut_vec.size(); i++) { |
|
|
|
|
await_ (fut_vec[i]); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sleep with delayed sleep implement |
|
|
|
|