4#include "../detail/task_adapters/result_helpers.hpp"
19 [[nodiscard]]
constexpr bool should_retry(std::size_t retry_count)
const noexcept {
23 template <
typename Raw>
24 [[nodiscard]]
static constexpr auto on_exhausted(Raw&& raw)
noexcept {
36 [[nodiscard]]
constexpr bool should_retry(std::size_t retry_count)
const noexcept {
40 template <
typename Raw>
41 [[nodiscard]]
static constexpr std::remove_cvref_t<Raw>
on_exhausted(Raw&& raw)
noexcept {
42 return std::forward<Raw>(raw);
50 [[nodiscard]]
static constexpr bool should_retry(std::size_t)
noexcept {
67template <
typename Task,
typename Policy>
75 constexpr retry_task(Task&& stored_task, Policy&& stored_policy)
76 noexcept(std::is_nothrow_move_constructible_v<Task> &&
77 std::is_nothrow_move_constructible_v<Policy>)
78 :
task(std::move(stored_task)),
79 policy(std::move(stored_policy)) {}
81 constexpr retry_task(
const Task& stored_task,
const Policy& stored_policy)
82 noexcept(std::is_nothrow_copy_constructible_v<Task> &&
83 std::is_nothrow_copy_constructible_v<Policy>)
100 template <
typename Ctx,
typename Prev>
103 noexcept(
noexcept(
task.invoke_raw(ec)) &&
104 noexcept(
policy.should_retry(std::size_t {})) &&
109 using raw_value_t = std::remove_cvref_t<raw_result_t>;
112 "Wrapped task raw_result_type must match invoke_raw(exec_context<...>&) return type");
115 return task.invoke_raw(ec);
117 static_assert(!std::is_reference_v<raw_result_t>,
118 "with_retry(...) does not support retry-capable reference raw results");
120 std::size_t retry_count = 0;
123 raw_value_t raw =
task.invoke_raw(ec);
129 if (!policy.should_retry(retry_count)) {
138 template <
typename Ctx,
typename Prev,
typename U = Task>
139 requires direct_output_task<U, Ctx, Prev> && retry_policy<Policy>
143 noexcept(
task.invoke_into(ec, out)) &&
144 noexcept(policy.should_retry(std::size_t {})) &&
148 std::size_t retry_count = 0;
151 const auto step =
task.invoke_into(ec, out);
157 if (!policy.should_retry(retry_count)) {
162 if (out.has_value()) {
184template <
typename Task,
typename Policy>
185 requires retry_policy<std::decay_t<Policy>>
191 std::forward<Task>(
task),
192 std::forward<Policy>(policy)
Reports whether a task object exposes the raw execution protocol for a concrete exec_context.
Reports whether a retry policy exposes the minimal protocol required by with_retry(....
constexpr bool raw_result_requests_retry(const R &r) noexcept
typename declared_task_output< Task >::type declared_task_output_t
decltype(std::declval< Task >().invoke_raw(std::declval< exec_context< Ctx, Prev > & >())) raw_task_result_t
constexpr auto retry_exhausted_as_failure(const Raw &raw) noexcept
constexpr auto handle_retry_exhausted(const Policy &policy, Raw &&raw) noexcept
constexpr bool is_adapter_descriptor_v
constexpr auto with_retry(Task &&task, Policy &&policy)
Wraps a task so retry results are handled by a user retry policy.
constexpr auto task(F &&f)
Output sink passed to direct-output tasks.
Lightweight borrowed view used during execution.
Retry policy that allows a fixed number of retries and then preserves the final retry result unchange...
constexpr bool should_retry(std::size_t retry_count) const noexcept
static constexpr std::remove_cvref_t< Raw > on_exhausted(Raw &&raw) noexcept
Retry policy that allows a fixed number of additional retries.
static constexpr auto on_exhausted(Raw &&raw) noexcept
constexpr bool should_retry(std::size_t retry_count) const noexcept
Retry policy that keeps retrying for as long as the task requests it.
static constexpr bool should_retry(std::size_t) noexcept
Retry adapter that re-invokes a task when it returns retry.
constexpr decltype(auto) invoke_raw(exec_context< Ctx, Prev > &ec) noexcept(noexcept(task.invoke_raw(ec)) &&noexcept(policy.should_retry(std::size_t {})) &&noexcept(detail::handle_retry_exhausted(policy, std::declval< std::remove_cvref_t< detail::raw_task_result_t< Task &, Ctx, Prev > > >())))
Executes the wrapped task and re-runs it while policy permits.
constexpr retry_task(Task &&stored_task, Policy &&stored_policy) noexcept(std::is_nothrow_move_constructible_v< Task > &&std::is_nothrow_move_constructible_v< Policy >)
constexpr retry_task(const Task &stored_task, const Policy &stored_policy) noexcept(std::is_nothrow_copy_constructible_v< Task > &&std::is_nothrow_copy_constructible_v< Policy >)
constexpr step_result invoke_into(exec_context< Ctx, Prev > &ec, direct_out< detail::declared_task_output_t< U > > out) noexcept(noexcept(task.invoke_into(ec, out)) &&noexcept(policy.should_retry(std::size_t {})) &&noexcept(detail::handle_retry_exhausted(policy, step_result::retry())))
Represents the basic outcome of a task step.
static constexpr step_result retry() noexcept
Creates a retry result.