Revert D4982969: [Folly] Destroy promise/future callback functions before waking...
[folly.git] / folly / futures / Promise-inl.h
index 7019b72014598fd65c393e46fb94e1bb9f574a7e..c55d34ca66e48e069918c726ebcd2c1ea67d3ed5 100644 (file)
@@ -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.
@@ -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>
@@ -130,4 +133,12 @@ void Promise<T>::setWith(F&& func) {
   setTry(makeTryWith(std::forward<F>(func)));
 }
 
+template <class T>
+bool Promise<T>::isFulfilled() const noexcept {
+  if (core_) {
+    return core_->hasResult();
+  }
+  return true;
+}
+
 }