CppPromise is an experimental implementation of the JavaScript A+ Promise standard in C++. It is designed to make asynchornous code easier to write and maintain. There are several other implementations of this concept already (cpp-promise, q, PoolQueue). CppPromise is mostly an excuse for me to improve my tempalte meta-programming skills. However, it may have some features that make it useful to others.
- Header only
- Works on early C++11 compilers - (VS2013 in particular)
- Type-safe - Promise objects are strongly typed, and most mistakes should be caught at compile time.
- Framework agnostic - Does not have a bundled event system or timers. Feel free to use any framewok that makes sense (Boost.Asio, libuv, Qt, etc...)
CppPromise is extermly experimental at the moment. There is currently no documentation, almost no comments, and no tests.
Here is a code example
//Return an already resolved promise containing an int
Promise<int> testReturnInt()
{
return resolve(123);
}
//Return an already resolved promise containing a float
Promise<float> testReturnFloat()
{
return resolve(1.23f);
}
testReturnInt().then([](int iTest) {
REQUIRE(iTest == 123);
return testReturnFloat();
}).then([](float fTest) {
REQUIRE(fTest == Approx(1.23));
testReturnInt();
}).fail([](std::exception &e) {
std::cout << "Exception was thrown: " << e.what() << std::endl;
});