11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
18PROMEKI_NAMESPACE_BEGIN
36template <
typename T>
class Promise {
44 Promise(
const Promise &) =
delete;
45 Promise &operator=(
const Promise &) =
delete;
48 Promise(Promise &&other) =
default;
51 Promise &operator=(Promise &&other) =
default;
57 void setValue(T value) { _promise.set_value(std::move(value)); }
68 void setError(Error error) { _promise.set_exception(std::make_exception_ptr(PromiseError(error))); }
74 Future<T> future() {
return Future<T>(_promise.get_future()); }
77 std::promise<T> _promise;
83template <>
class Promise<void> {
91 Promise(
const Promise &) =
delete;
92 Promise &operator=(
const Promise &) =
delete;
93 Promise(Promise &&other) =
default;
94 Promise &operator=(Promise &&other) =
default;
99 void setValue() { _promise.set_value(); }
109 void setError(Error error) { _promise.set_exception(std::make_exception_ptr(PromiseError(error))); }
115 Future<void> future() {
return Future<void>(_promise.get_future()); }
118 std::promise<void> _promise;