Commit b6c0f8df authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Make Future<T>::delayed complete on correct executor 4/n: Remove Future::delayed

Summary:
Overall plan to modify Future<T>::delayed to complete on the same executor as the input future.

4/n: Remove Future::delayed completely to ensure that all users are on delayedUnsafe so that when we put delayed in with correct behaviour there is no incorrect use.

Reviewed By: marshallcline

Differential Revision: D8223327

fbshipit-source-id: c675d2d51afa2131eee5871afea45f1c6cc65a77
parent 84d98c46
...@@ -1734,16 +1734,6 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) { ...@@ -1734,16 +1734,6 @@ Future<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) {
// delayed // delayed
template <class T>
Future<T> Future<T>::delayed(Duration dur, Timekeeper* tk) {
return collectAllSemiFuture(*this, futures::sleep(dur, tk))
.toUnsafeFuture()
.then([](std::tuple<Try<T>, Try<Unit>> tup) {
Try<T>& t = std::get<0>(tup);
return makeFuture<T>(std::move(t));
});
}
template <class T> template <class T>
Future<T> Future<T>::delayedUnsafe(Duration dur, Timekeeper* tk) { Future<T> Future<T>::delayedUnsafe(Duration dur, Timekeeper* tk) {
return collectAllSemiFuture(*this, futures::sleep(dur, tk)) return collectAllSemiFuture(*this, futures::sleep(dur, tk))
......
...@@ -934,10 +934,6 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -934,10 +934,6 @@ class Future : private futures::detail::FutureBase<T> {
template <class E> template <class E>
Future<T> within(Duration, E exception, Timekeeper* = nullptr); Future<T> within(Duration, E exception, Timekeeper* = nullptr);
/// Delay the completion of this Future for at least this duration from
/// now. The optional Timekeeper is as with futures::sleep().
Future<T> delayed(Duration, Timekeeper* = nullptr);
/// Delay the completion of this Future for at least this duration from /// Delay the completion of this Future for at least this duration from
/// now. The optional Timekeeper is as with futures::sleep(). /// now. The optional Timekeeper is as with futures::sleep().
/// NOTE: Deprecated /// NOTE: Deprecated
......
...@@ -98,16 +98,6 @@ TEST(Timekeeper, futureWithinHandlesNullTimekeeperSingleton) { ...@@ -98,16 +98,6 @@ TEST(Timekeeper, futureWithinHandlesNullTimekeeperSingleton) {
EXPECT_THROW(f.get(), FutureNoTimekeeper); EXPECT_THROW(f.get(), FutureNoTimekeeper);
} }
TEST(Timekeeper, futureDelayed) {
auto t1 = now();
auto dur = makeFuture()
.delayed(one_ms)
.then([=]{ return now() - t1; })
.get();
EXPECT_GE(dur, one_ms);
}
TEST(Timekeeper, futureDelayedUnsafe) { TEST(Timekeeper, futureDelayedUnsafe) {
auto t1 = now(); auto t1 = now();
auto dur = auto dur =
...@@ -153,8 +143,14 @@ TEST(Timekeeper, futureWithinException) { ...@@ -153,8 +143,14 @@ TEST(Timekeeper, futureWithinException) {
TEST(Timekeeper, onTimeout) { TEST(Timekeeper, onTimeout) {
bool flag = false; bool flag = false;
makeFuture(42).delayed(10 * one_ms) makeFuture(42)
.onTimeout(zero_ms, [&]{ flag = true; return -1; }) .delayedUnsafe(10 * one_ms)
.onTimeout(
zero_ms,
[&] {
flag = true;
return -1;
})
.get(); .get();
EXPECT_TRUE(flag); EXPECT_TRUE(flag);
} }
...@@ -169,20 +165,23 @@ TEST(Timekeeper, onTimeoutComplete) { ...@@ -169,20 +165,23 @@ TEST(Timekeeper, onTimeoutComplete) {
TEST(Timekeeper, onTimeoutReturnsFuture) { TEST(Timekeeper, onTimeoutReturnsFuture) {
bool flag = false; bool flag = false;
makeFuture(42).delayed(10 * one_ms) makeFuture(42)
.onTimeout(zero_ms, [&]{ flag = true; return makeFuture(-1); }) .delayedUnsafe(10 * one_ms)
.onTimeout(
zero_ms,
[&] {
flag = true;
return makeFuture(-1);
})
.get(); .get();
EXPECT_TRUE(flag); EXPECT_TRUE(flag);
} }
TEST(Timekeeper, onTimeoutVoid) { TEST(Timekeeper, onTimeoutVoid) {
makeFuture().delayed(one_ms) makeFuture().delayedUnsafe(one_ms).onTimeout(zero_ms, [&] {});
.onTimeout(zero_ms, [&]{ makeFuture().delayedUnsafe(one_ms).onTimeout(zero_ms, [&] {
}); return makeFuture<Unit>(std::runtime_error("expected"));
makeFuture().delayed(one_ms) });
.onTimeout(zero_ms, [&]{
return makeFuture<Unit>(std::runtime_error("expected"));
});
// just testing compilation here // just testing compilation here
} }
...@@ -239,7 +238,7 @@ TEST(Timekeeper, executor) { ...@@ -239,7 +238,7 @@ TEST(Timekeeper, executor) {
TEST(Timekeeper, onTimeoutPropagates) { TEST(Timekeeper, onTimeoutPropagates) {
bool flag = false; bool flag = false;
EXPECT_THROW( EXPECT_THROW(
makeFuture(42).delayed(one_ms) makeFuture(42).delayedUnsafe(one_ms)
.onTimeout(zero_ms, [&]{ flag = true; }) .onTimeout(zero_ms, [&]{ flag = true; })
.get(), .get(),
FutureTimeout); FutureTimeout);
......
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