diff options
author | Determinant <ted.sybil@gmail.com> | 2018-02-04 15:16:58 -0500 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-02-04 15:16:58 -0500 |
commit | ac3a0030123a350bff490d69a4786954a9003686 (patch) | |
tree | 54d85b015739cef725a8eaec19d4678fa44f57d4 /test.cpp | |
parent | 7a95221366f1a2aef9414ae7484242726bb812a1 (diff) |
add `race`
Diffstat (limited to 'test.cpp')
-rw-r--r-- | test.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -63,7 +63,7 @@ int main() { printf("got resolved x = %d, output 12\n", x); return 12; }).then(f).then(a1).fail(a2).then(b1).fail(b2).then(g).then(a3, b3) - .then([](int x) { + .then([](int) { puts("void return is ok"); }).then([]() { puts("void parameter is ok"); @@ -102,8 +102,21 @@ int main() { return reason; }) .then([](const promise::values_t values) { - printf("finally %d\n", any_cast<int>(values[1])); + int x = any_cast<int>(values[1]); + printf("promise 1, 6 resolved %d\n", x); + return x + 1; }); + + auto pm8 = promise_t([](promise_t) { + puts("promsie 8 will never be resolved"); + }); + + auto pm9 = promise::race(std::vector<promise_t>{pm7, pm8}) + .then([](promise::pm_any_t value) { + printf("finally, promise 9 resolved with %d\n", + any_cast<int>(value)); + }); + puts("calling t4: resolve promise 3"); t4(); puts("calling t5: resolve promise 4"); |