/*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2015-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
std::swap(size_, other.size_);
std::swap(hasValue_, other.hasValue_);
std::swap(try_, other.try_);
+ std::swap(interruptHandler_, other.interruptHandler_);
std::swap(promises_, other.promises_);
return *this;
}
template <class T>
-Future<T> SharedPromise<T>::getFuture() {
+SemiFuture<T> SharedPromise<T>::getSemiFuture() {
std::lock_guard<std::mutex> g(mutex_);
size_++;
if (hasValue_) {
return makeFuture<T>(Try<T>(try_));
} else {
promises_.emplace_back();
- return promises_.back().getFuture();
+ if (interruptHandler_) {
+ promises_.back().setInterruptHandler(interruptHandler_);
+ }
+ return promises_.back().getSemiFuture();
}
}
+template <class T>
+Future<T> SharedPromise<T>::getFuture() {
+ return getSemiFuture().via(&folly::InlineExecutor::instance());
+}
+
template <class T>
template <class E>
typename std::enable_if<std::is_base_of<std::exception, E>::value>::type
if (hasValue_) {
return;
}
+ interruptHandler_ = fn;
for (auto& p : promises_) {
p.setInterruptHandler(fn);
}
{
std::lock_guard<std::mutex> g(mutex_);
if (hasValue_) {
- throw PromiseAlreadySatisfied();
+ throwPromiseAlreadySatisfied();
}
hasValue_ = true;
try_ = std::move(t);
template <class T>
bool SharedPromise<T>::isFulfilled() {
+ std::lock_guard<std::mutex> g(mutex_);
return hasValue_;
}
-}
+} // namespace folly