11USERVER_NAMESPACE_BEGIN
19class ResultStore
final {
28 const T&
Get()
const&;
41 std::optional<T> value_;
42 std::exception_ptr exception_;
49class ResultStore<
void>
final {
64 bool has_value_{
false};
65 std::exception_ptr exception_;
70 if (value_)
return std::move(*value_);
71 if (exception_) std::rethrow_exception(exception_);
72 throw std::logic_error(
"result store is not ready");
76const T& ResultStore<T>::
Get()
const& {
77 if (value_)
return *value_;
78 if (exception_) std::rethrow_exception(exception_);
79 throw std::logic_error(
"result store is not ready");
89 value_.emplace(std::move(value));
93void ResultStore<T>::
SetException(std::exception_ptr&& exception)
noexcept {
94 exception_ = std::move(exception);
98inline void ResultStore<
void>::
Retrieve() { Get(); }
100inline void ResultStore<
void>::Get()
const& {
101 if (has_value_)
return;
102 if (exception_) std::rethrow_exception(exception_);
103 throw std::logic_error(
"result store is not ready");
106inline void ResultStore<
void>::
SetValue()
noexcept { has_value_ =
true; }
108inline void ResultStore<
void>::
SetException(std::exception_ptr&& exception)
noexcept {
109 exception_ = std::move(exception);