YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
shared_future.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>, "SharedFuture 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:
15 SharedFuture() = default;
16
18 return _core != nullptr;
19 }
20
23 return GetFuture().Get();
24 }
25
28 auto [f, p] = MakeContract<V, E>();
29 _core->Attach(std::move(p));
30 return std::move(f);
31 }
32
35 auto [f, p] = MakeContractOn<V, E>(e);
36 _core->Attach(std::move(p));
37 return std::move(f);
38 }
39
40 void Attach(Promise<V, E>&& p) const {
42 _core->Attach(std::move(p));
43 }
44
45 /**
46 * Part of unsafe but internal API
47 */
49 }
50
51 private:
53};
54
55} // namespace yaclib
Provides a mechanism to access the result of async operations.
Definition future.hpp:232
Provides a mechanism to access the result of async operations.
Definition future.hpp:199
A intrusive pointer to objects with an embedded reference count.
Encapsulated return value from caller.
Definition result.hpp:90
SharedFuture(detail::SharedCorePtr< V, E > core) noexcept
Part of unsafe but internal API.
Future< V, E > GetFuture() const
FutureOn< V, E > GetFutureOn(IExecutor &e) const
bool Valid() const &noexcept
void Attach(Promise< V, E > &&p) const
Result< V, E > Get() const
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25