From ac3a0030123a350bff490d69a4786954a9003686 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 4 Feb 2018 15:16:58 -0500 Subject: add `race` --- test.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'test.cpp') diff --git a/test.cpp b/test.cpp index afa0f3f..737512e 100644 --- a/test.cpp +++ b/test.cpp @@ -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(values[1])); + int x = any_cast(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{pm7, pm8}) + .then([](promise::pm_any_t value) { + printf("finally, promise 9 resolved with %d\n", + any_cast(value)); + }); + puts("calling t4: resolve promise 3"); t4(); puts("calling t5: resolve promise 4"); -- cgit v1.2.3