olp-cpp-sdk  1.22.0
ExecutionContext.h
1 /*
2  * Copyright (C) 2022 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <utility>
23 
24 #include <olp/core/client/ApiError.h>
25 #include <olp/core/client/CancellationContext.h>
26 
27 namespace olp {
28 namespace thread {
29 
31 class CORE_API ExecutionContext final {
32  using CancelFuncType = std::function<void()>;
33  using ExecuteFuncType = std::function<client::CancellationToken()>;
34  using FailedCallback = std::function<void(client::ApiError)>;
35 
36  public:
39 
45  bool Cancelled() const;
46 
49 
51  void ExecuteOrCancelled(const ExecuteFuncType& execute_fn,
52  const CancelFuncType& cancel_fn = nullptr);
53 
64 
71  void SetFailedCallback(FailedCallback callback);
72 
82 
83  private:
84  class ExecutionContextImpl;
85  std::shared_ptr<ExecutionContextImpl> impl_;
86 };
87 
88 } // namespace thread
89 } // namespace olp
A wrapper around an internal error or HTTP status code.
Definition: ApiError.h:37
A wrapper that manages the cancellation state of an asynchronous operation in a thread-safe way.
Definition: CancellationContext.h:40
Cancels service requests.
Definition: CancellationToken.h:33
Handles the cancellation and final mechanisms.
Definition: ExecutionContext.h:31
void ExecuteOrCancelled(const ExecuteFuncType &execute_fn, const CancelFuncType &cancel_fn=nullptr)
ExecutionContext()
A default contructor, initializes the ExecutionContextImpl instance.
const client::CancellationContext & GetContext() const
Gets the CancellationContext object associated with this ExecutionContext instance.
bool Cancelled() const
Checks whether CancellationContext is cancelled.
void SetError(client::ApiError error)
Sets the error that is returned in the Finally method of the execution.
void SetFailedCallback(FailedCallback callback)
Sets a callback for SetError.
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24