aboutsummaryrefslogtreecommitdiff
path: root/test.cpp
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2018-06-28 16:47:49 -0400
committerDeterminant <ted.sybil@gmail.com>2018-06-28 16:47:49 -0400
commit924be7bb303bacae3eedd7610383e638d5b096d8 (patch)
tree541ab8b69157bb3c15d9072ecf5728e02fcfc477 /test.cpp
parentc63ace092b179c029865cd861f50b502fa0e2e26 (diff)
add an example
Diffstat (limited to 'test.cpp')
-rw-r--r--test.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/test.cpp b/test.cpp
index 3c2bfc9..7fa7f60 100644
--- a/test.cpp
+++ b/test.cpp
@@ -30,6 +30,21 @@ promise_t g(int x) {
return promise_t([](promise_t pm) {pm.resolve(1);});
}
+void test_fac() {
+ promise_t root;
+ promise_t t = root;
+ for (int i = 0; i < 10; i++)
+ t = t.then([](std::pair<int, int> p) {
+ p.first *= p.second;
+ p.second++;
+ return p;
+ });
+ t.then([](std::pair<int, int> p) {
+ printf("fac(%d) = %d\n", p.second, p.first);
+ });
+ root.resolve(std::make_pair(1, 1));
+}
+
int main() {
callback_t t1;
callback_t t2;
@@ -143,4 +158,5 @@ int main() {
t1();
puts("calling t2: resolve the second half of promise 1 (promise 2)");
t2();
+ test_fac();
}