Outline throw statements in folly/futures/
[folly.git] / folly / futures / Promise-inl.h
index 245b0d6fee6325472c670f818b92dbbd30a5b8b2..3c6ff17345965552b303bb943638fe0c046e0f4e 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.
 namespace folly {
 
 template <class T>
-Promise<T>::Promise() : retrieved_(false), core_(new detail::Core<T>())
-{}
+Promise<T> Promise<T>::makeEmpty() noexcept {
+  return Promise<T>(futures::detail::EmptyConstruct{});
+}
+
+template <class T>
+Promise<T>::Promise()
+    : retrieved_(false), core_(new futures::detail::Core<T>()) {}
 
 template <class T>
 Promise<T>::Promise(Promise<T>&& other) noexcept
@@ -44,18 +49,25 @@ Promise<T>& Promise<T>::operator=(Promise<T>&& other) noexcept {
 
 template <class T>
 void Promise<T>::throwIfFulfilled() {
-  if (!core_)
-    throw NoState();
-  if (core_->ready())
-    throw PromiseAlreadySatisfied();
+  if (!core_) {
+    throwNoState();
+  }
+  if (core_->ready()) {
+    throwPromiseAlreadySatisfied();
+  }
 }
 
 template <class T>
 void Promise<T>::throwIfRetrieved() {
-  if (retrieved_)
-    throw FutureAlreadyRetrieved();
+  if (retrieved_) {
+    throwFutureAlreadyRetrieved();
+  }
 }
 
+template <class T>
+Promise<T>::Promise(futures::detail::EmptyConstruct) noexcept
+    : retrieved_(false), core_(nullptr) {}
+
 template <class T>
 Promise<T>::~Promise() {
   detach();
@@ -131,7 +143,7 @@ void Promise<T>::setWith(F&& func) {
 }
 
 template <class T>
-bool Promise<T>::isFulfilled() {
+bool Promise<T>::isFulfilled() const noexcept {
   if (core_) {
     return core_->hasResult();
   }