19template <
typename V,
typename T>
24 static_assert(
Check<V>(),
"V should be valid");
27 static_assert(!std::is_same_v<V, typename T::Error>,
28 "V cannot be the same as the trait Error type, because callback dispatch would be ambiguous");
48 std::move(*this).Detach();
58 return _core !=
nullptr;
68 return !
_core->Empty();
71 void Get() & =
delete;
98 auto core = std::exchange(
_core,
nullptr);
99 return std::move(core->Get());
122 auto core = std::exchange(
_core,
nullptr);
123 return std::move(core->Get());
135 template <
typename Func>
138 "better way is use ThenInline(...) instead of Then(MakeInline(), ...)");
139 static constexpr auto CoreT = CoreType::ToUnique | CoreType::Call;
140 return detail::SetCallback<CoreT, true>(
_core, &
e, std::forward<Func>(
f));
147 auto* core =
_core.Release();
159 template <
typename Func>
161 static constexpr auto CoreT = CoreType::Detach;
162 detail::SetCallback<CoreT, false>(
_core,
nullptr, std::forward<Func>(
f));
173 template <
typename Func>
176 "better way is use DetachInline(...) instead of Detach(MakeInline(), ...)");
177 static constexpr auto CoreT = CoreType::Detach | CoreType::Call;
178 detail::SetCallback<CoreT, false>(
_core, &
e, std::forward<Func>(
f));
212template <
typename V,
typename T>
231 template <
typename Func>
233 static constexpr auto CoreT = CoreType::ToUnique;
234 return detail::SetCallback<CoreT, false>(this->_core,
nullptr, std::forward<Func>(
f));
246template <
typename V,
typename T>
264 return {std::move(this->_core)};
275 template <
typename Func>
277 static constexpr auto CoreT = CoreType::ToUnique;
278 return detail::SetCallback<CoreT, true>(this->_core,
nullptr, std::forward<Func>(
f));
288 template <
typename Func>
290 static constexpr auto CoreT = CoreType::ToUnique | CoreType::Call;
291 return detail::SetCallback<CoreT, true>(this->_core,
nullptr, std::forward<Func>(
f));
300 template <
typename Func>
302 static constexpr auto CoreT = CoreType::Detach | CoreType::Call;
303 detail::SetCallback<CoreT, false>(this->_core,
nullptr, std::forward<Func>(
f));
Provides a mechanism to access the result of async operations.
typename T::template Result< V > Result
const Result & Touch() const &noexcept
void Detach(IExecutor &e, Func &&f) &&
Attach the final continuation func to *this and Detach *this.
bool Ready() const &noexcept
Check that Result that corresponds to this Future is computed.
FutureBase()=default
The default constructor creates not a Valid Future.
FutureBase & operator=(FutureBase &&other) noexcept=default
void DetachInline(Func &&f) &&
Attach the final continuation func to *this and Detach *this.
void Get() const &&=delete
FutureBase & operator=(const FutureBase &)=delete
detail::UniqueCorePtr< V, T > _core
detail::UniqueCorePtr< V, T > & GetCore() noexcept
Method that get internal Core state.
bool Valid() const &noexcept
Check if this Future has Promise.
void Detach() &&noexcept
Disable calling Stop in destructor.
FutureBase(detail::UniqueCorePtr< V, T > core) noexcept
FutureBase(FutureBase &&other) noexcept=default
auto Then(IExecutor &e, Func &&f) &&
Attach the continuation func to *this.
Result Touch() &&noexcept
~FutureBase() noexcept
If Future is Valid then call Stop.
FutureBase(const FutureBase &)=delete
detail::UniqueHandle GetHandle() noexcept
Provides a mechanism to access the result of async operations.
void Detach(Func &&f) &&
Attach the final continuation func to *this and Detach *this.
Future< V, T > On(std::nullptr_t) &&noexcept
Specify executor for continuation.
auto Then(Func &&f) &&
Attach the continuation func to *this.
FutureOn(detail::UniqueCorePtr< V, T > core) noexcept
auto ThenInline(Func &&f) &&
Attach the continuation func to *this.
Provides a mechanism to access the result of async operations.
auto ThenInline(Func &&f) &&
Attach the continuation func to *this.
Future(detail::UniqueCorePtr< V, T > core) noexcept
A intrusive pointer to objects with an embedded reference count.
#define YACLIB_WARN(cond, message)
#define YACLIB_ASSERT(cond)
InlineCore & MakeDrop() noexcept
Contract< V, T > MakeContract()
Creates related future and promise.
YACLIB_INLINE std::enable_if_t<(... &&is_waitable_v< Waited >), void > Wait(Waited &... fs) noexcept
Wait until Ready becomes true.