projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
move futures/ScheduledExecutor to executors/ScheduledExecutor
[folly.git]
/
folly
/
futures
/
Promise-inl.h
diff --git
a/folly/futures/Promise-inl.h
b/folly/futures/Promise-inl.h
index b855d064e90a9b826b3459989d9029de9d38527c..5fe4ed2cb029c782c39e3f54ac9fa2fdb0fc2222 100644
(file)
--- a/
folly/futures/Promise-inl.h
+++ b/
folly/futures/Promise-inl.h
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 201
5
Facebook, Inc.
+ * Copyright 201
7
Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* 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 <class T>
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
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() {
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() {
}
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();
template <class T>
Promise<T>::~Promise() {
detach();
@@
-87,13
+99,7
@@
Promise<T>::setException(E const& e) {
template <class T>
void Promise<T>::setException(std::exception_ptr const& ep) {
template <class T>
void Promise<T>::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 <class T>
}
template <class T>
@@
-127,7
+133,15
@@
template <class T>
template <class F>
void Promise<T>::setWith(F&& func) {
throwIfFulfilled();
template <class F>
void Promise<T>::setWith(F&& func) {
throwIfFulfilled();
- setTry(makeTryFunction(std::forward<F>(func)));
+ setTry(makeTryWith(std::forward<F>(func)));
+}
+
+template <class T>
+bool Promise<T>::isFulfilled() const noexcept {
+ if (core_) {
+ return core_->hasResult();
+ }
+ return true;
}
}
}
}