#ifndef __PROMISERESOLVER_H__ #define __PROMISERESOLVER_H__ template class Promise; template class PromiseResolver { public: PromiseResolver(Promise promise) : m_d{promise.m_d} { } template void resolve(V &&value) { if (m_d) { assert(m_d->isPending()); m_d->resolve(std::forward(value)); m_d->dispatch(); } } void resolve() { if (m_d) { assert(m_d->isPending()); m_d->resolve(); m_d->dispatch(); } } template void reject(E &&error) { if (m_d) { assert(m_d->isPending()); m_d->reject(std::forward(error)); m_d->dispatch(); } } void reject() { if (m_d) { assert(m_d->isPending()); m_d->reject(PromiseUndefinedException{}); m_d->dispatch(); } } private: std::shared_ptr> m_d; }; template class PromiseResolve { public: PromiseResolve(PromiseResolver resolver) : m_resolver{std::move(resolver)} { } template void operator()(V &&value) const { m_resolver.resolve(std::forward(value)); } void operator()() const { m_resolver.resolve(); } private: mutable PromiseResolver m_resolver; }; template class PromiseReject { public: PromiseReject(PromiseResolver resolver) : m_resolver{std::move(resolver)} { } template void operator()(E &&error) const { m_resolver.reject(std::forward(error)); } void operator()() const { m_resolver.reject(); } private: mutable PromiseResolver m_resolver; }; #endif // __PROMISERESOLVER_H__