forked from tonttu/pledge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Promise.hpp
66 lines (44 loc) · 1.11 KB
/
Promise.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include "Future.hpp"
namespace Pledge {
template <typename T = void>
class Promise
{
public:
Promise();
Promise(const Promise&) = delete;
Promise& operator=(const Promise&) = delete;
Promise(Promise&&) = default;
Promise& operator=(Promise&&) = default;
template <typename Y>
Promise(Y&& t);
Future<T> future(Executor* executor = nullptr);
template <typename Y>
void setValue(Y&& y);
void setError(std::exception_ptr error);
template <typename E>
void setError(E&& e);
template <typename F>
void set(F&& f);
private:
std::shared_ptr<FutureDataType<T>> m_data;
};
template <>
class Promise<void>
{
public:
Promise();
Promise(void_type t);
Future<> future(Executor* executor = nullptr);
void setValue();
void setError(std::exception_ptr error);
template <typename E>
void setError(E&& e);
private:
std::shared_ptr<FutureData<void_type>> m_data;
};
// Create a new future from the result of 'f' executed in the given executor.
template <typename F>
auto via(Executor* executor, F&& f) -> FutureType<typename Type<F>::Ret>;
}
#include "details/PromiseImpl.hpp"