C++14 asynchronous allocation aware futures (supporting then, exception handling, coroutines and connections)
Contains various follow up fixes for version 4.0.0:
See the release notes here.
See the release notes here.
This is an unstable release
In version 2.0 the library was heavily improved in multiple ways:
Usually it is inconvenient to handle error codes and exceptions in an asynchronous context, as we all know std::future
supports error handling through exceptions already. We now introduce this capability to the continuable library while allowing error codes to be used as well.
Consider the function cti::continuable<> get_bad_continuable()
which always resolves through an error, then you may handle the error code or exception as following:
get_bad_continuable()
.then([] {
// ... never invoked
})
.then([] {
// ... never invoked as well
})
.fail([] (std::exception_ptr e) {
try {
std::rethrow_exception(e);
} catch(std::exception const& e) {
// Handle the exception here
}
});
Since a callback may be called through an error or result the cri::promise
class was added in order ro provide a similar interface to std::promise
:
auto http_request(std::string url) {
return cti::make_continuable<std::string>([url = std::move(url)](cti::promise<std::string> /*or auto&&*/ promise) {
// Perform the actual request through a different library,
// resolve the promise upon completion of the task.
promise.set_value("<html> ... </html>");
// ...or promise.set_exception(...);
});
}
co_await
supportExperimental coroutine (co_await
and co_return
) support was added, this is available on MSVC 2017 and Clang 5.0.
int i = co_await cti::make_continuable<int>([](auto&& promise) {
promise.set_value(0);
});
The library was improved in other ways:
constexpr
and noexcept
improvementsSince the overall library size was increased the headers were split into smaller chunks.
This is the second pre-release of the continuable library.
http_request("github.com")
.then([] {
// ...
});
http_request("github.com") >> http_request("atom.io")
.then([] (std::string github, std::string atom) {
// ...
});
This is the first public release of the continuable library and ships with: