X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ffutures%2FPromise-inl.h;h=5c06d3035a543f40c680aea8cc581c1f3394541f;hb=730db44fc0c60c573111449ac7213303f7ed223d;hp=751d9b4cb8d36f18a215ad600b331dace8aa9417;hpb=ca1e87ed0a85daf3abaf2ac423266e869f3961ec;p=folly.git diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index 751d9b4c..5c06d303 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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,21 +49,25 @@ 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(futures::detail::EmptyConstruct) noexcept + : retrieved_(false), core_(nullptr) {} + template Promise::~Promise() { detach(); @@ -67,8 +76,9 @@ Promise::~Promise() { template void Promise::detach() { if (core_) { - if (!retrieved_) + if (!retrieved_) { core_->detachFuture(); + } core_->detachPromise(); core_ = nullptr; } @@ -90,13 +100,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 @@ -134,11 +138,11 @@ void Promise::setWith(F&& func) { } template -bool Promise::isFulfilled() { +bool Promise::isFulfilled() const noexcept { if (core_) { return core_->hasResult(); } return true; } -} +} // namespace folly