YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
connect.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace yaclib {
9
10template <typename V, typename E>
12 static_assert(std::is_move_constructible_v<Result<V, E>>);
13 YACLIB_ASSERT(f.Valid());
14 YACLIB_ASSERT(p.Valid());
15 YACLIB_ASSERT(f.GetCore() != p.GetCore());
16 if (f.GetCore()->SetCallback(*p.GetCore().Get())) {
17 f.GetCore().Release();
18 p.GetCore().Release();
19 } else {
20 std::move(p).Set(std::move(f).Touch());
21 }
22}
23
24template <typename V, typename E>
26 YACLIB_ASSERT(f.Valid());
27 YACLIB_ASSERT(p.Valid());
28 if (f.GetCore()->SetCallback(*p.GetCore().Get())) {
29 p.GetCore().Release();
30 } else {
31 std::move(p).Set(f.Touch());
32 }
33}
34
35template <typename V, typename E>
37 YACLIB_ASSERT(f.Valid());
38 YACLIB_ASSERT(p.Valid());
39 if (f.GetCore()->SetCallback(*p.GetCore().Get())) {
40 f.GetCore().Release();
41 p.GetCore().Release();
42 } else {
43 std::move(p).Set(std::move(f).Touch());
44 }
45}
46
47template <typename V, typename E>
49 YACLIB_ASSERT(f.Valid());
50 YACLIB_ASSERT(p.Valid());
51 YACLIB_ASSERT(f.GetCore() != p.GetCore());
52 if (f.GetCore()->SetCallback(*p.GetCore().Get())) {
53 p.GetCore().Release();
54 } else {
55 std::move(p).Set(f.Touch());
56 }
57}
58
59template <typename V, typename E>
61 YACLIB_ASSERT(primary.Valid());
62 YACLIB_ASSERT(subsumed.Valid());
63 auto subsumed_core = subsumed.GetCore().Release();
64 std::ignore = primary.GetCore()->SetCallback(*subsumed_core);
65}
66
67template <typename V, typename E>
69 YACLIB_ASSERT(primary.Valid());
70 YACLIB_ASSERT(subsumed.Valid());
71 auto subsumed_core = subsumed.GetCore().Release();
72 std::ignore = primary.GetCore()->SetCallback(*subsumed_core);
73}
74
75} // namespace yaclib
Provides a mechanism to access the result of async operations.
Definition future.hpp:20
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
void Connect(FutureBase< V, E > &&f, Promise< V, E > &&p)
Definition connect.hpp:11
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25