X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ffutures%2FPromise-inl.h;h=45e6929a9152a7bc0bf4750cf7583e8da4a684e3;hb=b22d1721ed9c062e22b33936e13b39ed1507391a;hp=3c6ff17345965552b303bb943638fe0c046e0f4e;hpb=063b4a3d63f502ea716704321e6a9462686ccdbb;p=folly.git diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index 3c6ff173..45e6929a 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -76,18 +77,26 @@ Promise::~Promise() { template void Promise::detach() { if (core_) { - if (!retrieved_) + if (!retrieved_) { core_->detachFuture(); + } core_->detachPromise(); core_ = nullptr; } } template -Future Promise::getFuture() { +SemiFuture Promise::getSemiFuture() { throwIfRetrieved(); retrieved_ = true; - return Future(core_); + return SemiFuture(core_); +} + +template +Future Promise::getFuture() { + // An InlineExecutor approximates the old behaviour of continuations + // running inine on setting the value of the promise. + return getSemiFuture().via(&InlineExecutor::instance()); } template @@ -99,13 +108,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 @@ -150,4 +153,4 @@ bool Promise::isFulfilled() const noexcept { return true; } -} +} // namespace folly