13template <
typename V,
typename E>
18 static_assert(
Check<V>(),
"V should be valid");
19 static_assert(
Check<E>(),
"E should be valid");
20 static_assert(!std::is_same_v<V, E>,
"SharedFuture cannot be instantiated with same V and E, because it's ambiguous");
21 static_assert(std::is_copy_constructible_v<Result<V, E>>,
"Result should be copyable");
26 return _core !=
nullptr;
31 return !
_core->Empty();
37 if (
_core->GetRef() == 1) {
38 return std::move(
_core->Get());
55 if (
_core->GetRef() == 1) {
56 return std::move(
_core->Get());
70 template <
typename Func>
73 "better way is use ThenInline(...) instead of Then(MakeInline(), ...)");
74 static constexpr auto CoreT = CoreType::ToUnique | CoreType::Call;
75 return detail::SetCallback<CoreT, true>(
_core, &
e, std::forward<Func>(
f));
82 template <
typename Func>
84 static constexpr auto CoreT = CoreType::Detach;
85 detail::SetCallback<CoreT, false>(
_core,
nullptr, std::forward<Func>(
f));
88 template <
typename Func>
91 "better way is use SubscribeInline(...) instead of Subscribe(MakeInline(), ...)");
92 static constexpr auto CoreT = CoreType::Detach | CoreType::Call;
93 detail::SetCallback<CoreT, true>(
_core, &
e, std::forward<Func>(
f));
119template <
typename V,
typename E>
130 template <
typename Func>
132 static constexpr auto CoreT = CoreType::ToUnique;
133 return detail::SetCallback<CoreT, false>(this->_core,
nullptr, std::forward<Func>(
f));
139template <
typename V,
typename E>
153 return {std::move(this->_core)};
156 template <
typename Func>
158 static constexpr auto CoreT = CoreType::ToUnique;
159 return detail::SetCallback<CoreT, true>(this->_core,
nullptr, std::forward<Func>(
f));
162 template <
typename Func>
164 static constexpr auto CoreT = CoreType::ToUnique | CoreType::Call;
165 return detail::SetCallback<CoreT, true>(this->_core,
nullptr, std::forward<Func>(
f));
168 template <
typename Func>
170 static constexpr auto CoreT = CoreType::Detach | CoreType::Call;
171 detail::SetCallback<CoreT, false>(this->_core,
nullptr, std::forward<Func>(
f));
A intrusive pointer to objects with an embedded reference count.
Encapsulated return value from caller.
void Subscribe(IExecutor &e, Func &&f) const
void SubscribeInline(Func &&f) const
detail::SharedHandle GetHandle() const noexcept
SharedFutureBase(detail::SharedCorePtr< V, E > core) noexcept
Result< V, E > Get() &&noexcept
auto Then(IExecutor &e, Func &&f) const
SharedFutureBase()=default
detail::SharedCorePtr< V, E > _core
const detail::SharedCorePtr< V, E > & GetCore() const noexcept
detail::SharedCorePtr< V, E > & GetCore() noexcept
void Touch() const &&=delete
bool Ready() const noexcept
bool Valid() const noexcept
Result< V, E > Touch() &&noexcept
void Get() const &&=delete
auto ThenInline(Func &&f) const
auto Then(Func &&f) const
SharedFutureOn(detail::SharedCorePtr< V, E > core) noexcept
void Subscribe(Func &&f) const
SharedFuture< V, E > On(std::nullptr_t) &&noexcept
auto ThenInline(Func &&f) const
SharedFuture(detail::SharedCorePtr< V, E > core) noexcept
#define YACLIB_WARN(cond, message)
#define YACLIB_ASSERT(cond)
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.