Base module
provides classes and functions to create continuable_
Classes
-
template<typename Data, typename Annotation>
class cti::continuable_base
- The main class of the continuable library, it provides the functionality for chaining callbacks and continuations together to a unified hierarchy.
-
template<typename Data, typename Hint>
class cti::promise_base
- The promise_
base makes it possible to resolve an asynchronous continuable through it's result or through an error type.
Typedefs
-
using dispatch_error_tag = detail::types::dispatch_error_tag
- Represents a tag which can be placed first in a signature in order to overload callables with the asynchronous result as well as an error.
-
using error_type = detail::types::error_type
- Represents the type that is used as error type.
-
template<typename T>
using is_continuable = detail::base::is_continuable<T>
- Deduces to a true_type if the given type is a continuable_
base.
Functions
-
template<typename... Args, typename Continuation>
auto make_continuable(Continuation&& continuation) -> auto constexpr
- Creates a continuable_
base from a promise/callback taking function.
-
template<typename... Args>
auto make_ready_continuable() -> auto constexpr
- Returns a continuable_
base with no result which instantly resolves the promise with no values.
-
template<typename Result>
auto make_ready_continuable(Result&& result) -> auto constexpr
- Returns a continuable_
base with one result value which instantly resolves the promise with the given value.
-
template<typename FirstResult, typename SecondResult, typename... Rest>
auto make_ready_continuable(FirstResult&& first_result,
SecondResult&& second_result,
Rest&&... rest) -> auto constexpr
- Returns a continuable_
base with multiple result values which instantly resolves the promise with the given values.
-
template<typename... Signature, typename Exception>
auto make_exceptional_continuable(Exception&& exception) -> auto constexpr
- Returns a continuable_
base with the parameterized result which instantly resolves the promise with the given error type.
Typedef documentation
using dispatch_error_tag = detail::types::dispatch_error_tag
Represents a tag which can be placed first in a signature in order to overload callables with the asynchronous result as well as an error.
See the example below:
struct my_callable { void operator() (std::string result) { // ... } void operator() (cti::dispatch_error_tag, cti::error_type) { // ... } }; // Will receive errors and results continuable.next(my_callable{});
using error_type = detail::types::error_type
Represents the type that is used as error type.
By default this type deduces to std::exception_ptr. If CONTINUABLE_WITH_NO_EXCEPTIONS is defined the type will be a std::error_condition. A custom error type may be set through defining CONTINUABLE_WITH_CUSTOM_ERROR_TYPE.
template<typename T>
using is_continuable = detail::base::is_continuable<T>
Deduces to a true_type if the given type is a continuable_
Function documentation
template<typename... Args, typename Continuation>
auto make_continuable(Continuation&& continuation) constexpr
Creates a continuable_
| Template parameters | |
|---|---|
| Args | The types (signature hint) the given promise is resolved with.
|
| Continuation | |
| Parameters | |
| continuation | The continuation the continuable is created from. The continuation must be a callable type accepting a callback parameter which represents the object invokable with the asynchronous result of this continuable. auto ct = cti::make_continuable<std::string>([](auto&& promise) { promise.set_value("result"); }); The callback may be stored or moved. In some cases the callback may be copied if supported by the underlying callback chain, in order to invoke the call chain multiple times. It's recommended to accept any callback instead of erasing it. // Good practice: auto ct = cti::make_continuable<std::string>([](auto&& promise) { promise.set_value("result"); }); // Good practice using a callable object: struct Continuation { template<typename T> void operator() (T&& continuation) && { // ... } } auto ct = cti::make_continuable<std::string>(Continuation{}); // Bad practice (because of unnecessary type erasure): auto ct = cti::make_continuable<std::string>( [](cti::promise<std::string> promise) { promise.set_value("result"); }); |
| Returns | A continuable_ |
template<typename... Args>
auto make_ready_continuable() constexpr
Returns a continuable_
template<typename Result>
auto make_ready_continuable(Result&& result) constexpr
Returns a continuable_
template<typename FirstResult, typename SecondResult, typename... Rest>
auto make_ready_continuable(FirstResult&& first_result,
SecondResult&& second_result,
Rest&&... rest) constexpr
Returns a continuable_
template<typename... Signature, typename Exception>
auto make_exceptional_continuable(Exception&& exception) constexpr
Returns a continuable_
| Template parameters | |
|---|---|
| Signature | The fake signature of the returned continuable. |
| Exception | |
See an example below:
std::logic_error exception("Some issue!"); auto ptr = std::make_exception_ptr(exception); auto ct = cti::make_exceptional_continuable<int>(ptr);