Commit 55a896f5 authored by Marshall Cline's avatar Marshall Cline Committed by Facebook Github Bot

rvalueification of Future::onTimeout(...): 1/n

Summary:
This is part of "the great r-valuification of folly::Future":
* This is something we should do for safety in general.
* Several of folly::Future's methods are lvalue-qualified even though they act as though they are rvalue-qualified, that is, they provide a postcondition that says, in effect, callers should act as though the method invalidated its `this` object (regardless of whether that invalidation was actual or logical).
* This violates the C++ principle to "Express ideas directly in code" (see Core Guidelines), and generally makes it more confusing for callers as well as hiding the actual semantics from tools (linters, compilers, etc.).
* This dichotomy and confusion has manifested itself by some failures around D7840699 since lvalue-qualification hides that operation's move-out semantics - leads to some use of future operations that are really not correct, but are not obviously incorrect.
* The goal of rvalueification is to make sure methods that are logically rvalue-qualified are actually rvalue-qualified, which forces callsites to acknowledge that rvalueification, e.g., `std::move(f).onTimeout(...)` instead of `f.onTimeout(...)`. This syntactic change in the callsites forces callers to acknowledge the method's rvalue semantics.

Reviewed By: LeeHowes

Differential Revision: D9441928

fbshipit-source-id: 28cb393588fa32becb44c89c6afd0ed482f5cf7e
parent 018a9fe6
......@@ -1222,7 +1222,7 @@ Future<T> Future<T>::ensure(F&& func) && {
template <class T>
template <class F>
Future<T> Future<T>::onTimeout(Duration dur, F&& func, Timekeeper* tk) {
Future<T> Future<T>::onTimeout(Duration dur, F&& func, Timekeeper* tk) && {
return std::move(*this).within(dur, tk).template thenError<FutureTimeout>(
[funcw = std::forward<F>(func)](auto const&) mutable {
return std::forward<F>(funcw)();
......
......@@ -1522,7 +1522,12 @@ class Future : private futures::detail::FutureBase<T> {
/// i.e., as if `*this` was moved into RESULT.
/// - `RESULT.valid() == true`
template <class F>
Future<T> onTimeout(Duration, F&& func, Timekeeper* = nullptr);
Future<T> onTimeout(Duration, F&& func, Timekeeper* = nullptr) &&;
template <class F>
Future<T> onTimeout(Duration dur, F&& func, Timekeeper* tk = nullptr) & {
return std::move(*this).onTimeout(dur, std::forward<F>(func), tk);
}
/// Throw FutureTimeout if this Future does not complete within the given
/// duration from now. The optional Timekeeper is as with futures::sleep().
......
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