-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathchain_defer_test.cpp
More file actions
31 lines (27 loc) · 872 Bytes
/
chain_defer_test.cpp
File metadata and controls
31 lines (27 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "promise-cpp/promise.hpp"
#include <sstream>
#include <iostream>
promise::Promise writeTo(std::ostream& out) {
return promise::newPromise().then([&out](int value) {
out << value;
return promise::reject(std::string(" testErrorReason "));
}, [&out](const std::string& reason) {
out << reason;
return 456;
});
}
int main() {
promise::Promise d = promise::newPromise();
std::ostringstream out;
promise::Promise writeToOut = writeTo(out);
d.then(writeToOut).then(writeTo(out)).then(writeTo(out));
d.resolve(123);
std::string expected = "123 testErrorReason 456";
if (out.str() != expected) {
std::cout << "FAIL chain_defer_test got \"" << out.str() << "\", "
<< "expected \"" << expected << "\"\n";
return 1;
}
std::cout << "PASS\n";
return 0;
}