YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
shared_promise.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace yaclib {
6
7template <typename V, typename E>
9 static_assert(Check<V>(), "V should be valid");
10 static_assert(Check<E>(), "E should be valid");
11 static_assert(!std::is_same_v<V, E>, "Future cannot be instantiated with same V and E, because it's ambiguous");
12 static_assert(std::is_copy_constructible_v<Result<V, E>>, "Result should be copyable");
13
14 public:
16
19
22
24 return _core != nullptr;
25 }
26
27 template <typename... Args>
28 void Set(Args&&... args) && {
30
31 if constexpr (sizeof...(Args) == 0) {
32 _core->Store(std::in_place);
33 } else {
34 _core->Store(std::forward<Args>(args)...);
35 }
36
37 auto released = _core.Release();
38 // The result will always be null
39 std::ignore = released->template SetResult<false>();
40 }
41
43 if (Valid()) {
44 std::move(*this).Set(StopTag{});
45 }
46 }
47
48 /**
49 * Part of unsafe but internal API
50 */
51 explicit SharedPromise(detail::SharedCorePtr<V, E> core) noexcept : _core(std::move(core)) {
52 }
53
55 return _core;
56 }
57
58 private:
60};
61
62} // namespace yaclib
A intrusive pointer to objects with an embedded reference count.
void Set(Args &&... args) &&
bool Valid() const noexcept
detail::SharedCorePtr< V, E > & GetCore() noexcept
SharedPromise(detail::SharedCorePtr< V, E > core) noexcept
Part of unsafe but internal API.
SharedPromise() noexcept=default
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25