19template <
typename V,
typename E>
24 static_assert(
Check<V>(),
"V should be valid");
25 static_assert(
Check<E>(),
"E should be valid");
26 static_assert(!std::is_same_v<V, E>,
"Future cannot be instantiated with same V and E, because it's ambiguous");
46 std::move(*this).Detach();
56 return _core !=
nullptr;
66 return !
_core->Empty();
69 void Get() & =
delete;
96 auto core = std::exchange(
_core,
nullptr);
97 return std::move(core->Get());
120 auto core = std::exchange(
_core,
nullptr);
121 return std::move(core->Get());
133 template <
typename Func>
136 "better way is use ThenInline(...) instead of Then(MakeInline(), ...)");
137 static constexpr auto CoreT = CoreType::ToUnique | CoreType::Call;
138 return detail::SetCallback<CoreT, true>(
_core, &
e, std::forward<Func>(
f));
145 auto* core =
_core.Release();
157 template <
typename Func>
159 static constexpr auto CoreT = CoreType::Detach;
160 detail::SetCallback<CoreT, false>(
_core,
nullptr, std::forward<Func>(
f));
171 template <
typename Func>
174 "better way is use DetachInline(...) instead of Detach(MakeInline(), ...)");
175 static constexpr auto CoreT = CoreType::Detach | CoreType::Call;
176 detail::SetCallback<CoreT, false>(
_core, &
e, std::forward<Func>(
f));
209template <
typename V,
typename E>
228 template <
typename Func>
230 static constexpr auto CoreT = CoreType::ToUnique;
231 return detail::SetCallback<CoreT, false>(this->_core,
nullptr, std::forward<Func>(
f));
243template <
typename V,
typename E>
261 return {std::move(this->_core)};
272 template <
typename Func>
274 static constexpr auto CoreT = CoreType::ToUnique;
275 return detail::SetCallback<CoreT, true>(this->_core,
nullptr, std::forward<Func>(
f));
285 template <
typename Func>
287 static constexpr auto CoreT = CoreType::ToUnique | CoreType::Call;
288 return detail::SetCallback<CoreT, true>(this->_core,
nullptr, std::forward<Func>(
f));
297 template <
typename Func>
299 static constexpr auto CoreT = CoreType::Detach | CoreType::Call;
300 detail::SetCallback<CoreT, false>(this->_core,
nullptr, std::forward<Func>(
f));
Provides a mechanism to access the result of async operations.
void DetachInline(Func &&f) &&
Attach the final continuation func to *this and Detach *this.
Result< V, E > Get() &&noexcept
FutureBase()=default
The default constructor creates not a Valid Future.
FutureBase & operator=(const FutureBase &)=delete
~FutureBase() noexcept
If Future is Valid then call Stop.
detail::UniqueCorePtr< V, E > _core
FutureBase(detail::UniqueCorePtr< V, E > core) noexcept
bool Valid() const &noexcept
Check if this Future has Promise.
Result< V, E > Touch() &&noexcept
FutureBase(FutureBase &&other) noexcept=default
void Detach() &&noexcept
Disable calling Stop in destructor.
void Detach(IExecutor &e, Func &&f) &&
Attach the final continuation func to *this and Detach *this.
auto Then(IExecutor &e, Func &&f) &&
Attach the continuation func to *this.
detail::UniqueCorePtr< V, E > & GetCore() noexcept
Method that get internal Core state.
detail::UniqueHandle GetHandle() noexcept
FutureBase(const FutureBase &)=delete
FutureBase & operator=(FutureBase &&other) noexcept=default
const Result< V, E > & Touch() const &noexcept
bool Ready() const &noexcept
Check that Result that corresponds to this Future is computed.
void Get() const &&=delete
Provides a mechanism to access the result of async operations.
Future< V, E > On(std::nullptr_t) &&noexcept
Specify executor for continuation.
void Detach(Func &&f) &&
Attach the final continuation func to *this and Detach *this.
FutureOn(detail::UniqueCorePtr< V, E > core) noexcept
auto ThenInline(Func &&f) &&
Attach the continuation func to *this.
auto Then(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, E > core) noexcept
A intrusive pointer to objects with an embedded reference count.
Encapsulated return value from caller.
#define YACLIB_WARN(cond, message)
#define YACLIB_ASSERT(cond)
InlineCore & MakeDrop() noexcept
Contract< V, E > 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.