Commit 0779c7fa authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Remove Executor* APIs

Summary: Executor::KeepAlive<> is now implicitly constructible from Executor*.

Reviewed By: capickett

Differential Revision: D13954744

fbshipit-source-id: 523a860a337429a995152dc7171c0f6e8be8cecb
parent 293afa64
...@@ -871,11 +871,6 @@ Future<T> SemiFuture<T>::via( ...@@ -871,11 +871,6 @@ Future<T> SemiFuture<T>::via(
return newFuture; return newFuture;
} }
template <class T>
Future<T> SemiFuture<T>::via(Executor* executor, int8_t priority) && {
return std::move(*this).via(getKeepAliveToken(executor), priority);
}
template <class T> template <class T>
Future<T> SemiFuture<T>::toUnsafeFuture() && { Future<T> SemiFuture<T>::toUnsafeFuture() && {
return std::move(*this).via(&InlineExecutor::instance()); return std::move(*this).via(&InlineExecutor::instance());
...@@ -1042,11 +1037,6 @@ Future<T> Future<T>::via(Executor::KeepAlive<> executor, int8_t priority) && { ...@@ -1042,11 +1037,6 @@ Future<T> Future<T>::via(Executor::KeepAlive<> executor, int8_t priority) && {
return newFuture; return newFuture;
} }
template <class T>
Future<T> Future<T>::via(Executor* executor, int8_t priority) && {
return std::move(*this).via(getKeepAliveToken(executor), priority);
}
template <class T> template <class T>
Future<T> Future<T>::via(Executor::KeepAlive<> executor, int8_t priority) & { Future<T> Future<T>::via(Executor::KeepAlive<> executor, int8_t priority) & {
this->throwIfInvalid(); this->throwIfInvalid();
...@@ -1065,11 +1055,6 @@ Future<T> Future<T>::via(Executor::KeepAlive<> executor, int8_t priority) & { ...@@ -1065,11 +1055,6 @@ Future<T> Future<T>::via(Executor::KeepAlive<> executor, int8_t priority) & {
return std::move(f).via(std::move(executor), priority); return std::move(f).via(std::move(executor), priority);
} }
template <class T>
Future<T> Future<T>::via(Executor* executor, int8_t priority) & {
return via(getKeepAliveToken(executor), priority);
}
template <typename T> template <typename T>
template <typename R, typename Caller, typename... Args> template <typename R, typename Caller, typename... Args>
Future<typename isFuture<R>::Inner> Future<T>::then( Future<typename isFuture<R>::Inner> Future<T>::then(
...@@ -1332,15 +1317,6 @@ Future<T>::onError(F&& func) && { ...@@ -1332,15 +1317,6 @@ Future<T>::onError(F&& func) && {
.via(&InlineExecutor::instance()); .via(&InlineExecutor::instance());
} }
template <class Func>
auto via(Executor* x, Func&& func) -> Future<
typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner> {
// TODO make this actually more performant. :-P #7260175
return via(x).thenValue([f = std::forward<Func>(func)](auto&&) mutable {
return std::forward<Func>(f)();
});
}
template <class Func> template <class Func>
auto via(Executor::KeepAlive<> x, Func&& func) -> Future< auto via(Executor::KeepAlive<> x, Func&& func) -> Future<
typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner> { typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner> {
...@@ -1412,10 +1388,6 @@ Future<T> makeFuture(Try<T> t) { ...@@ -1412,10 +1388,6 @@ Future<T> makeFuture(Try<T> t) {
} }
// via // via
Future<Unit> via(Executor* executor, int8_t priority) {
return makeFuture().via(executor, priority);
}
Future<Unit> via(Executor::KeepAlive<> executor, int8_t priority) { Future<Unit> via(Executor::KeepAlive<> executor, int8_t priority) {
return makeFuture().via(std::move(executor), priority); return makeFuture().via(std::move(executor), priority);
} }
...@@ -1844,13 +1816,6 @@ auto window(size_t times, F func, size_t n) ...@@ -1844,13 +1816,6 @@ auto window(size_t times, F func, size_t n)
return window(futures::detail::WindowFakeVector(times), std::move(func), n); return window(futures::detail::WindowFakeVector(times), std::move(func), n);
} }
template <class Collection, class F, class ItT, class Result>
std::vector<Future<Result>>
window(Executor* executor, Collection input, F func, size_t n) {
return window(
getKeepAliveToken(executor), std::move(input), std::move(func), n);
}
template <class Collection, class F, class ItT, class Result> template <class Collection, class F, class ItT, class Result>
std::vector<Future<Result>> std::vector<Future<Result>>
window(Executor::KeepAlive<> executor, Collection input, F func, size_t n) { window(Executor::KeepAlive<> executor, Collection input, F func, size_t n) {
......
...@@ -417,10 +417,6 @@ class FutureBase { ...@@ -417,10 +417,6 @@ class FutureBase {
// Must be called either before attaching a callback or after the callback // Must be called either before attaching a callback or after the callback
// has already been invoked, but not concurrently with anything which might // has already been invoked, but not concurrently with anything which might
// trigger invocation of the callback. // trigger invocation of the callback.
void setExecutor(Executor* x, int8_t priority = Executor::MID_PRI) {
getCore().setExecutor(x, priority);
}
void setExecutor( void setExecutor(
Executor::KeepAlive<> x, Executor::KeepAlive<> x,
int8_t priority = Executor::MID_PRI) { int8_t priority = Executor::MID_PRI) {
...@@ -669,8 +665,6 @@ class SemiFuture : private futures::detail::FutureBase<T> { ...@@ -669,8 +665,6 @@ class SemiFuture : private futures::detail::FutureBase<T> {
bool wait(Duration dur) &&; bool wait(Duration dur) &&;
/// Returns a Future which will call back on the other side of executor. /// Returns a Future which will call back on the other side of executor.
Future<T> via(Executor* executor, int8_t priority = Executor::MID_PRI) &&;
Future<T> via( Future<T> via(
Executor::KeepAlive<> executor, Executor::KeepAlive<> executor,
int8_t priority = Executor::MID_PRI) &&; int8_t priority = Executor::MID_PRI) &&;
...@@ -1088,8 +1082,6 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1088,8 +1082,6 @@ class Future : private futures::detail::FutureBase<T> {
/// ///
/// - `valid() == false` /// - `valid() == false`
/// - `RESULT.valid() == true` /// - `RESULT.valid() == true`
Future<T> via(Executor* executor, int8_t priority = Executor::MID_PRI) &&;
Future<T> via( Future<T> via(
Executor::KeepAlive<> executor, Executor::KeepAlive<> executor,
int8_t priority = Executor::MID_PRI) &&; int8_t priority = Executor::MID_PRI) &&;
...@@ -1107,8 +1099,6 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1107,8 +1099,6 @@ class Future : private futures::detail::FutureBase<T> {
/// - `valid() == true` /// - `valid() == true`
/// - `RESULT.valid() == true` /// - `RESULT.valid() == true`
/// - when `this` gets fulfilled, it automatically fulfills RESULT /// - when `this` gets fulfilled, it automatically fulfills RESULT
Future<T> via(Executor* executor, int8_t priority = Executor::MID_PRI) &;
Future<T> via( Future<T> via(
Executor::KeepAlive<> executor, Executor::KeepAlive<> executor,
int8_t priority = Executor::MID_PRI) &; int8_t priority = Executor::MID_PRI) &;
...@@ -1218,9 +1208,9 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1218,9 +1208,9 @@ class Future : private futures::detail::FutureBase<T> {
/// i.e., as if `*this` was moved into RESULT. /// i.e., as if `*this` was moved into RESULT.
/// - `RESULT.valid() == true` /// - `RESULT.valid() == true`
template <class Arg> template <class Arg>
auto then(Executor* x, Arg&& arg) && { auto then(Executor::KeepAlive<> x, Arg&& arg) && {
auto oldX = this->getExecutor(); auto oldX = getKeepAliveToken(this->getExecutor());
this->setExecutor(x); this->setExecutor(std::move(x));
// TODO(T29171940): thenImplementation here is ambiguous // TODO(T29171940): thenImplementation here is ambiguous
// as then used to be but that is better than keeping then in the public // as then used to be but that is better than keeping then in the public
...@@ -1228,21 +1218,24 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1228,21 +1218,24 @@ class Future : private futures::detail::FutureBase<T> {
using R = futures::detail::callableResult<T, Arg&&>; using R = futures::detail::callableResult<T, Arg&&>;
return std::move(*this) return std::move(*this)
.thenImplementation(std::forward<Arg>(arg), R{}) .thenImplementation(std::forward<Arg>(arg), R{})
.via(oldX); .via(std::move(oldX));
} }
template <class R, class Caller, class... Args> template <class R, class Caller, class... Args>
auto then(Executor* x, R (Caller::*func)(Args...), Caller* instance) && { auto then(
auto oldX = this->getExecutor(); Executor::KeepAlive<> x,
this->setExecutor(x); R (Caller::*func)(Args...),
Caller* instance) && {
auto oldX = getKeepAliveToken(this->getExecutor());
this->setExecutor(std::move(x));
return std::move(*this).then(func, instance).via(oldX); return std::move(*this).then(func, instance).via(std::move(oldX));
} }
template <class Arg, class... Args> template <class Arg, class... Args>
[[deprecated( [[deprecated(
"must be rvalue-qualified, e.g., std::move(future).then(...)")]] auto "must be rvalue-qualified, e.g., std::move(future).then(...)")]] auto
then(Executor* x, Arg&& arg, Args&&... args) & = delete; then(Executor::KeepAlive<> x, Arg&& arg, Args&&... args) & = delete;
/// When this Future has completed, execute func which is a function that /// When this Future has completed, execute func which is a function that
/// can be called with `Try<T>&&` (often a lambda with parameter type /// can be called with `Try<T>&&` (often a lambda with parameter type
...@@ -1894,12 +1887,14 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1894,12 +1887,14 @@ class Future : private futures::detail::FutureBase<T> {
/// i.e., as if `*this` was moved into RESULT. /// i.e., as if `*this` was moved into RESULT.
/// - `RESULT.valid() == true` /// - `RESULT.valid() == true`
template <class Callback, class... Callbacks> template <class Callback, class... Callbacks>
auto auto thenMultiWithExecutor(
thenMultiWithExecutor(Executor* x, Callback&& fn, Callbacks&&... fns) && { Executor::KeepAlive<> x,
Callback&& fn,
Callbacks&&... fns) && {
// thenMultiExecutor with two callbacks is // thenMultiExecutor with two callbacks is
// via(x).then(a).thenMulti(b, ...).via(oldX) // via(x).then(a).thenMulti(b, ...).via(oldX)
auto oldX = this->getExecutor(); auto oldX = getKeepAliveToken(this->getExecutor());
this->setExecutor(x); this->setExecutor(std::move(x));
// TODO(T29171940): Switch to thenImplementation here. It is ambiguous // TODO(T29171940): Switch to thenImplementation here. It is ambiguous
// as then used to be but that is better than keeping then in the public // as then used to be but that is better than keeping then in the public
// API. // API.
...@@ -1907,13 +1902,13 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1907,13 +1902,13 @@ class Future : private futures::detail::FutureBase<T> {
return std::move(*this) return std::move(*this)
.thenImplementation(std::forward<Callback>(fn), R{}) .thenImplementation(std::forward<Callback>(fn), R{})
.thenMulti(std::forward<Callbacks>(fns)...) .thenMulti(std::forward<Callbacks>(fns)...)
.via(oldX); .via(std::move(oldX));
} }
template <class Callback> template <class Callback>
auto thenMultiWithExecutor(Executor* x, Callback&& fn) && { auto thenMultiWithExecutor(Executor::KeepAlive<> x, Callback&& fn) && {
// thenMulti with one callback is just a then with an executor // thenMulti with one callback is just a then with an executor
return std::move(*this).then(x, std::forward<Callback>(fn)); return std::move(*this).then(std::move(x), std::forward<Callback>(fn));
} }
/// Moves-out `*this`, creating/returning a corresponding SemiFuture. /// Moves-out `*this`, creating/returning a corresponding SemiFuture.
...@@ -2044,9 +2039,9 @@ class Timekeeper { ...@@ -2044,9 +2039,9 @@ class Timekeeper {
}; };
template <class T> template <class T>
std::pair<Promise<T>, Future<T>> makePromiseContract(Executor* e) { std::pair<Promise<T>, Future<T>> makePromiseContract(Executor::KeepAlive<> e) {
auto p = Promise<T>(); auto p = Promise<T>();
auto f = p.getSemiFuture().via(e); auto f = p.getSemiFuture().via(std::move(e));
return std::make_pair(std::move(p), std::move(f)); return std::make_pair(std::move(p), std::move(f));
} }
......
...@@ -314,10 +314,6 @@ Future<T> makeFuture(Try<T> t); ...@@ -314,10 +314,6 @@ Future<T> makeFuture(Try<T> t);
* *
* @returns a void Future that will call back on the given executor * @returns a void Future that will call back on the given executor
*/ */
inline Future<Unit> via(
Executor* executor,
int8_t priority = Executor::MID_PRI);
inline Future<Unit> via( inline Future<Unit> via(
Executor::KeepAlive<> executor, Executor::KeepAlive<> executor,
int8_t priority = Executor::MID_PRI); int8_t priority = Executor::MID_PRI);
...@@ -325,10 +321,6 @@ inline Future<Unit> via( ...@@ -325,10 +321,6 @@ inline Future<Unit> via(
/// Execute a function via the given executor and return a future. /// Execute a function via the given executor and return a future.
/// This is semantically equivalent to via(executor).then(func), but /// This is semantically equivalent to via(executor).then(func), but
/// easier to read and slightly more efficient. /// easier to read and slightly more efficient.
template <class Func>
auto via(Executor*, Func&& func) -> Future<
typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner>;
template <class Func> template <class Func>
auto via(Executor::KeepAlive<>, Func&& func) -> Future< auto via(Executor::KeepAlive<>, Func&& func) -> Future<
typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner>; typename isFutureOrSemiFuture<decltype(std::declval<Func>()())>::Inner>;
...@@ -472,15 +464,6 @@ template < ...@@ -472,15 +464,6 @@ template <
class Result = typename invoke_result_t<F, ItT&&>::value_type> class Result = typename invoke_result_t<F, ItT&&>::value_type>
std::vector<Future<Result>> window(Collection input, F func, size_t n); std::vector<Future<Result>> window(Collection input, F func, size_t n);
template <
class Collection,
class F,
class ItT = typename std::iterator_traits<
typename Collection::iterator>::value_type,
class Result = typename invoke_result_t<F, ItT&&>::value_type>
std::vector<Future<Result>>
window(Executor* executor, Collection input, F func, size_t n);
template < template <
class Collection, class Collection,
class F, class F,
......
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