YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
connect.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
yaclib/async/future.hpp
>
4
#include <
yaclib/async/promise.hpp
>
5
#include <
yaclib/async/shared_future.hpp
>
6
#include <
yaclib/async/shared_promise.hpp
>
7
8
namespace
yaclib
{
9
10
template
<
typename
V,
typename
E>
11
void
Connect
(
FutureBase<V, E>
&&
f
,
Promise<V, E>
&&
p
) {
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
24
template
<
typename
V,
typename
E>
25
void
Connect
(
const
SharedFutureBase<V, E>
&
f
,
Promise<V, E>
&&
p
) {
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
35
template
<
typename
V,
typename
E>
36
void
Connect
(
FutureBase<V, E>
&&
f
,
SharedPromise<V, E>
&&
p
) {
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
47
template
<
typename
V,
typename
E>
48
void
Connect
(
const
SharedFutureBase<V, E>
&
f
,
SharedPromise<V, E>
&&
p
) {
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
59
template
<
typename
V,
typename
E>
60
void
Connect
(
SharedPromise<V, E>
&
primary
,
Promise<V, E>
&&
subsumed
) {
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
67
template
<
typename
V,
typename
E>
68
void
Connect
(
SharedPromise<V, E>
&
primary
,
SharedPromise<V, E>
&&
subsumed
) {
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
future.hpp
shared_future.hpp
yaclib::FutureBase
Provides a mechanism to access the result of async operations.
Definition
future.hpp:20
yaclib::Promise
Definition
promise.hpp:10
yaclib::SharedFutureBase
Definition
shared_future.hpp:14
yaclib::SharedPromise
Definition
shared_promise.hpp:8
YACLIB_ASSERT
#define YACLIB_ASSERT(cond)
Definition
log.hpp:85
yaclib
Definition
base_core.hpp:15
yaclib::Connect
void Connect(FutureBase< V, E > &&f, Promise< V, E > &&p)
Definition
connect.hpp:11
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
promise.hpp
shared_promise.hpp
include
yaclib
async
connect.hpp
Generated by
1.9.8