diff options
author | Determinant <ted.sybil@gmail.com> | 2018-02-11 19:28:09 -0500 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-02-11 19:28:09 -0500 |
commit | 3ac928b90e7dd3f11f92490edac283c6e2bc6fda (patch) | |
tree | 93a6753afa56774c9b8ecac2cfaabd7979b99bdd /test.cpp | |
parent | 9da19de63af8876e8cfaed4abe5a9a6f957986a7 (diff) |
add rejection example
Diffstat (limited to 'test.cpp')
-rw-r--r-- | test.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -97,10 +97,6 @@ int main() { }); auto pm7 = promise::all(std::vector<promise_t>{pm1, pm6}) - .fail([](int reason) { - printf("reason: %d\n", reason); - return reason; - }) .then([](const promise::values_t values) { int x = any_cast<int>(values[1]); printf("promise 1, 6 resolved %d\n", x); @@ -113,10 +109,30 @@ int main() { auto pm9 = promise::race(std::vector<promise_t>{pm7, pm8}) .then([](promise::pm_any_t value) { - printf("finally, promise 9 resolved with %d\n", + printf("promise 9 resolved with %d\n", any_cast<int>(value)); + }) + .then([]() { + puts("rejecting with value -1"); + return promise_t([](promise_t pm) { + pm.reject(-1); + }); + }) + .then([]() { + puts("this line should not appear in the output"); + }) + .then([](int) { + puts("this line should not appear in the outputs"); + }) + .fail([](int reason) { + printf("reason: %d\n", reason); + return reason + 1; + }).then([](){ + puts("this line should not appear in the outputs"); + }, + [](int reason) { + printf("reason: %d\n", reason); }); - puts("calling t4: resolve promise 3"); t4(); puts("calling t5: resolve promise 4"); |