Alignet in readme

nonsync_wait
mbandic 4 months ago
parent 8b23bd6728
commit 4f674467d2
  1. 38
      README.md

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

Loading…
Cancel
Save