X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ffutures%2FPromise-inl.h;h=5fe4ed2cb029c782c39e3f54ac9fa2fdb0fc2222;hb=dbf0c41058bf6f45ed016856515700842ae73f1a;hp=61d4d933e2e1234fc3cffb52d198613e4ecccf77;hpb=8e110a76171f5204d63ce3dbd283589f8914fe44;p=folly.git diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index 61d4d933..5fe4ed2c 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -25,8 +25,13 @@ namespace folly { template -Promise::Promise() : retrieved_(false), core_(new detail::Core()) -{} +Promise Promise::makeEmpty() noexcept { + return Promise(futures::detail::EmptyConstruct{}); +} + +template +Promise::Promise() + : retrieved_(false), core_(new futures::detail::Core()) {} template Promise::Promise(Promise&& other) noexcept @@ -44,23 +49,23 @@ Promise& Promise::operator=(Promise&& other) noexcept { template void Promise::throwIfFulfilled() { - if (UNLIKELY(!core_)) { - throw NoState(); + if (!core_) { + throwNoState(); } - if (UNLIKELY(core_->ready())) { - throw PromiseAlreadySatisfied(); + if (core_->ready()) { + throwPromiseAlreadySatisfied(); } } template void Promise::throwIfRetrieved() { - if (UNLIKELY(retrieved_)) { - throw FutureAlreadyRetrieved(); + if (retrieved_) { + throwFutureAlreadyRetrieved(); } } template -Promise::Promise(detail::EmptyConstruct) noexcept +Promise::Promise(futures::detail::EmptyConstruct) noexcept : retrieved_(false), core_(nullptr) {} template @@ -94,13 +99,7 @@ Promise::setException(E const& e) { template void Promise::setException(std::exception_ptr const& ep) { - try { - std::rethrow_exception(ep); - } catch (const std::exception& e) { - setException(exception_wrapper(std::current_exception(), e)); - } catch (...) { - setException(exception_wrapper(std::current_exception())); - } + setException(exception_wrapper::from_exception_ptr(ep)); } template