9 #include <boost/asio.hpp>
15 template<
class Exec,
class T>
21 struct AsioPromiseHelper
24 using PromiseType = AsioPromise<Exec, T>;
30 constexpr T &&operator()(T &&t)
const {
31 return std::forward<T>(t);
36 template<
class Exec,
class T>
41 template<
class FuncT,
class PromiseT,
class ResolveT>
46 auto res = func(p.get());
47 using ResT = decltype(res);
48 if constexpr (isPromise<ResT>) {
51 [w=WaitHelper<detail::IdentityFunc, ResT, ResolveT>{
54 detail::IdentityFunc{},
81 void operator()(ValT val)
const {
82 using ResT = std::decay_t<decltype(val)>;
83 if constexpr (isPromise<ResT>) {
84 auto w = WaitHelper<detail::IdentityFunc, ResT, ResolveHelper>{
87 detail::IdentityFunc{},
92 p->set_value(std::move(val));
97 std::shared_ptr<std::promise<T>> p;
102 , m_executor(
std::move(executor)) {
104 m_val = p.get_future().share();
105 p.set_value(std::move(value));
111 , m_executor(
std::move(executor)) {
112 auto p = std::make_shared<std::promise<T>>();
113 m_val = p->get_future().share();
114 auto resolve = ResolveHelper{m_executor, p};
118 [=, callback=std::forward<Func>(callback),
119 resolve=std::move(resolve),
120 guard=boost::asio::make_work_guard(m_executor)]() {
127 template<
class FuncT>
134 [=, func=std::forward<FuncT>(func), *
this](
auto resolve) {
135 auto waitHelper = WaitHelper<std::decay_t<FuncT>,
137 std::decay_t<decltype(resolve)>>{
148 return m_val.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
156 std::shared_future<T> m_val;
161 detail::AsioPromiseHelper<Exec>::template PromiseType>
164 detail::AsioPromiseHelper<Exec>::template PromiseType>;
171 , m_executor(executor)
176 , m_executor(that.m_executor)
181 , m_executor(
std::move(that.m_executor))
185 m_executor = that.m_executor;
190 m_executor = std::move(that.m_executor);
194 template<
class T,
class FuncT>
196 return PromiseT<T>(m_executor, std::forward<FuncT>(func));
Definition: promise-interface.hpp:74
Definition: asio-promise-handler.hpp:162
AsioPromiseHandler(Exec executor)
Definition: asio-promise-handler.hpp:169
PromiseT< T > create(FuncT &&func)
Definition: asio-promise-handler.hpp:195
PromiseT< T > createResolved(T val)
Definition: asio-promise-handler.hpp:200
AsioPromiseHandler & operator=(const AsioPromiseHandler &that)
Definition: asio-promise-handler.hpp:184
AsioPromiseHandler(const AsioPromiseHandler &that)
Definition: asio-promise-handler.hpp:174
AsioPromiseHandler(AsioPromiseHandler &&that)
Definition: asio-promise-handler.hpp:179
AsioPromiseHandler & operator=(AsioPromiseHandler &&that)
Definition: asio-promise-handler.hpp:189
Definition: asio-promise-handler.hpp:38
bool ready() const
Definition: asio-promise-handler.hpp:147
T get() const
Definition: asio-promise-handler.hpp:151
AsioPromise(Exec executor, Func &&callback)
Definition: asio-promise-handler.hpp:109
auto then(FuncT &&func) -> AsioPromise< Exec, PromiseThenResult< FuncT, typename BaseT::DataT >>
Definition: asio-promise-handler.hpp:128
AsioPromise(Exec executor, T value)
Definition: asio-promise-handler.hpp:100
Definition: promise-interface.hpp:210
Definition: location.hpp:10
AsioPromiseHandler(Exec) -> AsioPromiseHandler< Exec >
typename detail::PromiseThenResultT< T, P >::type PromiseThenResult
Definition: promise-interface.hpp:67
Definition: clientutil.hpp:217