diff options
author | Determinant <ted.sybil@gmail.com> | 2018-01-31 17:45:09 -0500 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-01-31 17:45:09 -0500 |
commit | 4900f7a7533ca0d70db7dd5cb40d3fc8c5996a04 (patch) | |
tree | 1e235fb88b3feac440bcbaecd5cc810c76525a4e /test.cpp | |
parent | f97660608a0df24cb1200ac7d9c6b19ccb4620e3 (diff) |
update to a better interface and reduce the use of type erasures
Diffstat (limited to 'test.cpp')
-rw-r--r-- | test.cpp | 38 |
1 files changed, 18 insertions, 20 deletions
@@ -12,25 +12,26 @@ int main() { puts("pm1"); //t1 = [pm]() {pm.reject(5);}; t1 = [pm]() {pm.resolve(5);}; - }).then(std::function<int(int)>([](int x) { + }).then([](int x) { printf("%d\n", x); return 6; - })).then(std::function<int(int)>([](int y) { + }).then([](int y) { printf("%d\n", y); return 0; - })).then(std::function<promise_t(int)>([&t2](int x) { + }).then([&t2](int x) { auto pm2 = promise_t([x, &t2](promise_t pm2) { printf("pm2 %d\n", x); t2 = [pm2]() {pm2.resolve(std::string("hello"));}; }); return pm2; - })).then(std::function<int(std::string)>([](std::string s) { + }).then([](std::string s) { printf("%s\n", s.c_str()); return 10; - })).then(std::function<promise::None(int)>([](int x) { + }).then([](int x) { printf("%d\n", x); return promise::none; - })); + }); + auto p1 = promise_t([&t4](promise_t pm) { puts("p1"); t4 = [pm]() {pm.resolve(1);}; @@ -47,25 +48,22 @@ int main() { }); auto p4 = promise::all(std::vector<promise_t>{p1, p2, p3}) - .then(std::function<int(promise::values_t)>( - [](const promise::values_t values) { + .then([](const promise::values_t values) { printf("%d %s %s\n", std::any_cast<int>(values[0]), std::any_cast<std::string>(values[1]).c_str(), std::any_cast<std::string>(values[2]).c_str()); - return 100; - })); + return 100; + }); auto p5 = promise::all(std::vector<promise_t>{pm, p4}) - .fail(std::function<int(int)>( - [](int reason) { - printf("reason: %d\n", reason); - return reason; - })) - .then(std::function<promise::None(promise::values_t)>( - [](const promise::values_t values) { - printf("finally %d\n", std::any_cast<int>(values[1])); - return promise::none; - })); + .fail([](int reason) { + printf("reason: %d\n", reason); + return reason; + }) + .then([](const promise::values_t values) { + printf("finally %d\n", std::any_cast<int>(values[1])); + return promise::none; + }); puts("calling t"); t4(); puts("calling t2"); |