27class ExecutionContext;
30template <
typename ResultType>
34 if (!finally_callback_) {
41 if (impl_.Cancelled()) {
42 const auto finally_callback = std::move(finally_callback_);
43 if (finally_callback) {
57 const auto finally_callback = std::move(finally_callback_);
58 if (finally_callback) {
59 finally_callback(std::move(error));
63 impl_.Run([=](
void* input,
bool cancelled) {
66 const auto finally_callback = std::move(finally_callback_);
67 if (finally_callback) {
71 finally_callback(std::move(*
static_cast<ResultType*
>(input)));
77template <
typename ResultType>
79 FinallyCallbackType finally_callback) {
80 finally_callback_ = std::move(finally_callback);
84template <
typename NewType>
88 using NewResultType = internal::RemoveRefAndConst<NewType>;
89 return {[=](
void*, CallbackType callback) {
90 func(context, [callback](NewResultType input) {
91 callback(
static_cast<NewResultType*
>(&input));
95 auto in = *
static_cast<NewResultType*
>(input);
96 auto result = std::make_unique<NewResultType>(std::move(in));
97 return internal::MakeUntypedUnique(std::move(result));
101template <
typename Callable>
104 using NewResultType = internal::AsyncResultType<Callable>;
105 using Function = internal::TypeToFunctionInput<NewResultType>;
106 return Then(std::function<
void(Function)>(std::forward<Callable>(task)));
109template <
typename ResultType>
110template <
typename Callable>
113 using NewResultType = internal::DeducedType<Callable>;
114 using Function = internal::TypeToFunctionInput<NewResultType>;
119template <
typename ResultType>
120template <
typename NewType>
123 std::function<
void(NewType)>)>
125 using NewResultType = internal::RemoveRefAndConst<NewType>;
126 const auto context = impl_.GetExecutionContext();
129 {[=](
void* input, CallbackType callback) {
130 auto in = *
static_cast<ResultType*
>(input);
131 task(std::move(context), std::move(in),
132 [=](NewResultType arg) { callback(
static_cast<void*
>(&arg)); });
135 auto in = *
static_cast<NewResultType*
>(input);
136 auto result = std::make_unique<NewResultType>(std::move(in));
137 return internal::MakeUntypedUnique(std::move(result));
141template <
typename ResultType>
143 if (!finally_callback_) {
147 auto context = impl_.GetExecutionContext();
152template <
typename ResultType>
155 std::function<
void(
ExecutionContext, std::function<
void(ResultType)>)> task)
156 : impl_(scheduler, context,
157 Continuation<void>::ToAsyncTask(context, std::move(task))) {}
159template <
typename ResultType>
161 : impl_(std::move(continuation)) {}
A wrapper around an internal error or HTTP status code.
Definition ApiError.h:37
static ApiError Cancelled(const char *message="Cancelled")
Creates the ApiError instance with the cancelled error code and description.
Definition ApiError.h:47
Cancels service requests.
Definition CancellationToken.h:33
A generic template for Continuation.
Definition Continuation.h:140
Continuation< internal::DeducedType< Callable > > Then(Callable task)
Adds the next asynchronous task to the ContinuationImpl instance.
Definition Continuation.inl:111
client::CancellationToken CancelToken()
Provides a token to cancel the task.
Definition Continuation.inl:142
void Run()
Starts the execution of the task continuation chain.
Definition Continuation.inl:31
Continuation()=default
The default constructor of Continuation<ResultType>.
Continuation & Finally(FinallyCallbackType finally_callback)
Handles the finalization of the Continuation instance and sets a callback for it.
Definition Continuation.inl:78
Handles the cancellation and final mechanisms.
Definition ExecutionContext.h:31
Provides mechanisms to create a chain of tasks and start, cancel, and finalize an execution.
Definition Continuation.h:46
std::pair< AsyncTaskType, TaskType > ContinuationTask
An alias for a pair of task continuation chain types.
Definition Continuation.h:61
Rules all the other namespaces.
Definition AppleSignInProperties.h:24