Result module
provides the result class and corresponding utility functions to work with the result of an asynchronous operation which can possibly yield:
- no result: If the operation didn't finish
- a value: If the operation finished successfully
- an exception: If the operation finished with an exception or was cancelled.
Classes
- struct cti::empty_result
- A class which is convertible to any result and that definitely holds no value so the real result gets invalidated when this object is passed to it.
- struct cti::cancellation_result
- A class which is convertible to any result and that definitely holds a default constructed exception which signals the cancellation of the asynchronous control flow.
- class cti::exceptional_result
- A class which is convertible to any result and that holds an exception which is then passed to the converted result object.
-
template<typename... T>class cti::result
- The result class can carry the three kinds of results an asynchronous operation possibly can return, it's implemented in a variant like data structure which is also specialized to hold arbitrary arguments.
Typedefs
- using void_arg_t = detail::void_arg_t
- A tag which represents present void values in result.
Functions
-
template<std::size_t I, typename... T>auto get(result<T...>& result) -> decltype(auto)
- Returns the value at position I of the given result.
-
template<std::size_t I, typename... T>auto get(result<T...> const& result) -> decltype(auto)
- Returns the value at position I of the given result.
-
template<std::size_t I, typename... T>auto get(result<T...>&& result) -> decltype(auto)
- Returns the value at position I of the given result.
-
template<typename... T, typename Result = result<detail::traits::unrefcv_t<T>...>>auto make_result(T && ... values) -> Result
- Creates a present result from the given values.
- auto make_result(exception_arg_t, exception_t exception) -> exceptional_result
- Creates an exceptional_
result from the given exception.
Typedef documentation
using void_arg_t = detail::void_arg_t
A tag which represents present void values in result.
Function documentation
template<typename... T, typename Result = result<detail::traits::unrefcv_t<T>...>>
Result make_result(T && ... values)
Creates a present result from the given values.
This could be used to pass the result of the next handler to the same asynchronous path it came from as shown below:
make_ready_continuable().next([&](auto&&... args) { result<> captured = make_result(std::forward<decltype(args)>(args)...); return shutdown().then([captured = std::move(captured)]() mutable { return std::move(captured); }); });
exceptional_result make_result(exception_arg_t, exception_t exception)
Creates an exceptional_
This could be used to pass the result of the next handler to the same asynchronous path it came from as shown below:
make_ready_continuable().next([&](auto&&... args) { result<> captured = make_result(std::forward<decltype(args)>(args)...); return shutdown().then([captured = std::move(captured)]() mutable { return std::move(captured); }); });