notification queue read -> readNoInt
[folly.git] / folly / futures / Promise-inl.h
index b57e952f93a4161911519828b8d6382a26fe8674..751d9b4cb8d36f18a215ad600b331dace8aa9417 100644 (file)
@@ -44,16 +44,19 @@ Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept {
 
 template <class T>
 void Promise<T>::throwIfFulfilled() {
-  if (!core_)
+  if (UNLIKELY(!core_)) {
     throw NoState();
-  if (core_->ready())
+  }
+  if (UNLIKELY(core_->ready())) {
     throw PromiseAlreadySatisfied();
+  }
 }
 
 template <class T>
 void Promise<T>::throwIfRetrieved() {
-  if (retrieved_)
+  if (UNLIKELY(retrieved_)) {
     throw FutureAlreadyRetrieved();
+  }
 }
 
 template <class T>
@@ -109,7 +112,7 @@ void Promise<T>::setInterruptHandler(
 }
 
 template <class T>
-void Promise<T>::fulfilTry(Try<T> t) {
+void Promise<T>::setTry(Try<T>&& t) {
   throwIfFulfilled();
   core_->setResult(std::move(t));
 }
@@ -120,22 +123,22 @@ void Promise<T>::setValue(M&& v) {
   static_assert(!std::is_same<T, void>::value,
                 "Use setValue() instead");
 
-  fulfilTry(Try<T>(std::forward<M>(v)));
+  setTry(Try<T>(std::forward<M>(v)));
 }
 
 template <class T>
-void Promise<T>::setValue() {
-  static_assert(std::is_same<T, void>::value,
-                "Use setValue(value) instead");
-
-  fulfilTry(Try<void>());
+template <class F>
+void Promise<T>::setWith(F&& func) {
+  throwIfFulfilled();
+  setTry(makeTryWith(std::forward<F>(func)));
 }
 
 template <class T>
-template <class F>
-void Promise<T>::fulfil(F&& func) {
-  throwIfFulfilled();
-  fulfilTry(makeTryFunction(std::forward<F>(func)));
+bool Promise<T>::isFulfilled() {
+  if (core_) {
+    return core_->hasResult();
+  }
+  return true;
 }
 
 }