Commit abc3bfdf authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

One Core alias in Promise and Future

Summary: [Folly] One `Core` alias in `Promise` and `Future`. Having two aliases was odd.

Reviewed By: marshallcline

Differential Revision: D8472386

fbshipit-source-id: fb2241445e100927602faed9d89775534d06d10a
parent a8990a74
......@@ -147,13 +147,13 @@ FutureBase<T>::FutureBase(Future<T>&& other) noexcept : core_(other.core_) {
template <class T>
template <class T2, typename>
FutureBase<T>::FutureBase(T2&& val)
: core_(CoreType::make(Try<T>(std::forward<T2>(val)))) {}
: core_(Core::make(Try<T>(std::forward<T2>(val)))) {}
template <class T>
template <typename T2>
FutureBase<T>::FutureBase(
typename std::enable_if<std::is_same<Unit, T2>::value>::type*)
: core_(CoreType::make(Try<T>(T()))) {}
: core_(Core::make(Try<T>(T()))) {}
template <class T>
template <
......@@ -161,7 +161,7 @@ template <
typename std::enable_if<std::is_constructible<T, Args&&...>::value, int>::
type>
FutureBase<T>::FutureBase(in_place_t, Args&&... args)
: core_(CoreType::make(in_place, std::forward<Args>(args)...)) {}
: core_(Core::make(in_place, std::forward<Args>(args)...)) {}
template <class T>
void FutureBase<T>::assign(FutureBase<T>&& other) noexcept {
......@@ -723,7 +723,7 @@ typename std::
template <class T>
SemiFuture<T> makeSemiFuture(Try<T>&& t) {
return SemiFuture<T>(SemiFuture<T>::CoreType::make(std::move(t)));
return SemiFuture<T>(SemiFuture<T>::Core::make(std::move(t)));
}
// This must be defined after the constructors to avoid a bug in MSVC
......@@ -748,7 +748,7 @@ typename SemiFuture<T>::DeferredExecutor* SemiFuture<T>::getDeferredExecutor()
}
template <class T>
void SemiFuture<T>::releaseDeferredExecutor(corePtr core) {
void SemiFuture<T>::releaseDeferredExecutor(Core* core) {
if (!core) {
return;
}
......@@ -1287,7 +1287,7 @@ makeFuture(E const& e) {
template <class T>
Future<T> makeFuture(Try<T>&& t) {
return Future<T>(Future<T>::CoreType::make(std::move(t)));
return Future<T>(Future<T>::Core::make(std::move(t)));
}
// via
......
......@@ -346,18 +346,17 @@ class FutureBase {
template <class>
friend class Future;
using CoreType = futures::detail::Core<T>;
using corePtr = CoreType*;
using Core = futures::detail::Core<T>;
// Throws FutureInvalid if there is no shared state object; else returns it
// by ref.
//
// Implementation methods should usually use this instead of `this->core_`.
// The latter should be used only when you need the possibly-null pointer.
CoreType& getCore() {
Core& getCore() {
return getCoreImpl(*this);
}
CoreType const& getCore() const {
Core const& getCore() const {
return getCoreImpl(*this);
}
......@@ -387,9 +386,9 @@ class FutureBase {
// shared core state object
// usually you should use `getCore()` instead of directly accessing `core_`.
corePtr core_;
Core* core_;
explicit FutureBase(corePtr obj) : core_(obj) {}
explicit FutureBase(Core* obj) : core_(obj) {}
explicit FutureBase(futures::detail::EmptyConstruct) noexcept;
......@@ -876,14 +875,14 @@ class SemiFuture : private futures::detail::FutureBase<T> {
template <class>
friend class Future;
using typename Base::corePtr;
using Base::setExecutor;
using Base::throwIfInvalid;
using typename Base::Core;
template <class T2>
friend SemiFuture<T2> makeSemiFuture(Try<T2>&&);
explicit SemiFuture(corePtr obj) : Base(obj) {}
explicit SemiFuture(Core* obj) : Base(obj) {}
explicit SemiFuture(futures::detail::EmptyConstruct) noexcept
: Base(futures::detail::EmptyConstruct{}) {}
......@@ -891,7 +890,7 @@ class SemiFuture : private futures::detail::FutureBase<T> {
// Throws FutureInvalid if !this->core_
DeferredExecutor* getDeferredExecutor() const;
static void releaseDeferredExecutor(corePtr core);
static void releaseDeferredExecutor(Core* core);
};
template <class T>
......@@ -1821,9 +1820,9 @@ class Future : private futures::detail::FutureBase<T> {
using Base::setExecutor;
using Base::throwIfContinued;
using Base::throwIfInvalid;
using typename Base::corePtr;
using typename Base::Core;
explicit Future(corePtr obj) : Base(obj) {}
explicit Future(Core* obj) : Base(obj) {}
explicit Future(futures::detail::EmptyConstruct) noexcept
: Base(futures::detail::EmptyConstruct{}) {}
......
......@@ -42,7 +42,7 @@ Promise<T> Promise<T>::makeEmpty() noexcept {
}
template <class T>
Promise<T>::Promise() : retrieved_(false), core_(CoreType::make()) {}
Promise<T>::Promise() : retrieved_(false), core_(Core::make()) {}
template <class T>
Promise<T>::Promise(Promise<T>&& other) noexcept
......
......@@ -20,6 +20,7 @@
#include <folly/Portability.h>
#include <folly/Try.h>
#include <folly/futures/detail/Core.h>
#include <folly/lang/Exception.h>
namespace folly {
......@@ -416,18 +417,17 @@ class Promise {
// Whether the Future has been retrieved (a one-time operation).
bool retrieved_;
using CoreType = typename Future<T>::CoreType;
using corePtr = typename Future<T>::corePtr;
using Core = futures::detail::Core<T>;
// Throws PromiseInvalid if there is no shared state object; else returns it
// by ref.
//
// Implementation methods should usually use this instead of `this->core_`.
// The latter should be used only when you need the possibly-null pointer.
CoreType& getCore() {
Core& getCore() {
return getCoreImpl(core_);
}
CoreType const& getCore() const {
Core const& getCore() const {
return getCoreImpl(core_);
}
......@@ -441,7 +441,7 @@ class Promise {
// shared core state object
// usually you should use `getCore()` instead of directly accessing `core_`.
corePtr core_;
Core* core_;
explicit Promise(futures::detail::EmptyConstruct) noexcept;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment