10#include "Arp/System/Core/Exception.hpp"
11#include "Arp/System/Core/TypeName.hxx"
16namespace Arp {
namespace System {
namespace Nm {
namespace Internal
32 class IExceptionWrapper
35 virtual ~IExceptionWrapper() =
default;
36 virtual void ReThrowException() = 0;
42 template<
typename ExceptionType>
43 class ExceptionWrapper :
public IExceptionWrapper
46 explicit ExceptionWrapper(
const ExceptionType& e) : exception(e)
50 ~ExceptionWrapper()
override =
default;
52 void ReThrowException()
override
54 throw this->exception;
58 ExceptionType exception;
66 bool isCreatedByPromise =
false;
67 std::atomic<bool> valueHasBeenSet;
68 std::unique_ptr<IExceptionWrapper> exception;
90 virtual ImplBase& GetPImpl() = 0;
91 virtual const ImplBase& GetPImpl()
const = 0;
92 void CheckForValueAndException()
const;
94 template<
typename ExceptionType>
95 void SetException(
const ExceptionType& e);
97 void Clear(
bool isValid);
101template<
typename ExceptionType>
102void FutureBase::SetException(
const ExceptionType& e)
104 this->GetPImpl().exception = std::make_unique<ExceptionWrapper<ExceptionType>>(e);
105 this->GetPImpl().valueHasBeenSet.store(
true);
117 friend Internal::Promise<T>;
119 struct Impl :
public ImplBase
124 static Future CreateByPromise();
144 void SetValue(
const T& value);
146 Impl& GetPImpl()
override
148 return *(this->pImpl);
151 const Impl& GetPImpl()
const override
153 return *(this->pImpl);
157 std::shared_ptr<Impl> pImpl{std::make_shared<Impl>()};
162Future<T> Future<T>::CreateByPromise()
165 result.pImpl->isCreatedByPromise =
true;
173 this->CheckForValueAndException();
174 return this->GetPImpl().value;
181 this->GetPImpl().value = value;
182 this->GetPImpl().valueHasBeenSet.store(
true);
194 friend Internal::Promise<void>;
195 using Impl = ImplBase;
197 static Future CreateByPromise();
221 Impl& GetPImpl()
override;
222 const Impl& GetPImpl()
const override;
225 std::shared_ptr<Impl> pImpl;
Base class with common behavior for Future<T> and Future<void>
Definition: Future.hpp:28
const bool HasValue() const
Returns true, if a value or an exception has been set
const bool HasException() const
Returns true, if an exception has been set
const bool IsValid() const
Returns true, if this Future has an assiciated Promise
Future()
Constructs an invalid Future
void GetValue() const
Gets the void result of the asynchronous function call
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:115
const T GetValue() const
Returns the value set by the associated Promise
Definition: Future.hpp:171
Future()=default
Constructs an invalid Future
Root namespace for the PLCnext API