10#include "Arp/System/Core/Exception.hpp"
11#include "Arp/System/Core/TypeName.hxx"
16namespace Arp {
namespace System {
namespace Nm {
namespace Internal
34 bool isCreatedByPromise =
false;
35 std::atomic<bool> valueHasBeenSet;
36 std::exception_ptr exception;
49 bool HasValue()
const;
50 bool HasException()
const;
53 virtual ImplBase& GetPImpl() = 0;
54 virtual const ImplBase& GetPImpl()
const = 0;
55 void CheckForValueAndException()
const;
57 void SetException(std::exception_ptr e);
58 void Clear(
bool isValid);
70 friend Internal::Promise<T>;
72 struct Impl :
public ImplBase
77 static Future CreateByPromise();
94 void SetValue(
const T& value);
96 Impl& GetPImpl()
override
98 return *(this->pImpl);
101 const Impl& GetPImpl()
const override
103 return *(this->pImpl);
107 std::shared_ptr<Impl> pImpl{std::make_shared<Impl>()};
112Future<T> Future<T>::CreateByPromise()
115 result.pImpl->isCreatedByPromise =
true;
125 this->CheckForValueAndException();
126 return this->GetPImpl().value;
133 this->GetPImpl().value = value;
134 this->GetPImpl().valueHasBeenSet.store(
true);
146 friend Internal::Promise<void>;
147 using Impl = ImplBase;
149 static Future CreateByPromise();
160 void GetValue()
const;
165 Impl& GetPImpl()
override;
166 const Impl& GetPImpl()
const override;
169 std::shared_ptr<Impl> pImpl;
Base class with common behavior for Future<T> and Future<void>
Definition: Future.hpp:28
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:68
T GetValue() const
Returns the value set by the associated Promise
Definition: Future.hpp:123
Future()=default
Constructs an invalid Future
Root namespace for the PLCnext API