X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ffutures%2FPromise-inl.h;h=5fe4ed2cb029c782c39e3f54ac9fa2fdb0fc2222;hb=dbf0c41058bf6f45ed016856515700842ae73f1a;hp=b855d064e90a9b826b3459989d9029de9d38527c;hpb=c5dabddc2f804c33dfeb7e248d697bf69f6c90cf;p=folly.git diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index b855d064..5fe4ed2c 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,18 +49,25 @@ Promise& Promise::operator=(Promise&& other) noexcept { template void Promise::throwIfFulfilled() { - if (!core_) - throw NoState(); - if (core_->ready()) - throw PromiseAlreadySatisfied(); + if (!core_) { + throwNoState(); + } + if (core_->ready()) { + throwPromiseAlreadySatisfied(); + } } template void Promise::throwIfRetrieved() { - if (retrieved_) - throw FutureAlreadyRetrieved(); + if (retrieved_) { + throwFutureAlreadyRetrieved(); + } } +template +Promise::Promise(futures::detail::EmptyConstruct) noexcept + : retrieved_(false), core_(nullptr) {} + template Promise::~Promise() { detach(); @@ -87,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 @@ -127,7 +133,15 @@ template template void Promise::setWith(F&& func) { throwIfFulfilled(); - setTry(makeTryFunction(std::forward(func))); + setTry(makeTryWith(std::forward(func))); +} + +template +bool Promise::isFulfilled() const noexcept { + if (core_) { + return core_->hasResult(); + } + return true; } }