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

Add futures::sleepUnsafe to allow migration to sleep returning a SemiFuture

Summary: Clone sleep as sleepUnsafe as a codemod target to migrate callsites to a SemiFuture-returning sleep.

Reviewed By: yfeldblum

Differential Revision: D14072020

fbshipit-source-id: 3dc88378732ca203c168ea2e4371508ee376cc43
parent 97baa137
...@@ -53,5 +53,9 @@ Future<Unit> sleep(Duration dur, Timekeeper* tk) { ...@@ -53,5 +53,9 @@ Future<Unit> sleep(Duration dur, Timekeeper* tk) {
return tk->after(dur); return tk->after(dur);
} }
Future<Unit> sleepUnsafe(Duration dur, Timekeeper* tk) {
return sleep(dur, tk);
}
} // namespace futures } // namespace futures
} // namespace folly } // namespace folly
...@@ -46,6 +46,7 @@ namespace futures { ...@@ -46,6 +46,7 @@ namespace futures {
/// needed. If your program never uses any timeouts or other time-based /// needed. If your program never uses any timeouts or other time-based
/// Futures you will pay no Timekeeper thread overhead. /// Futures you will pay no Timekeeper thread overhead.
Future<Unit> sleep(Duration, Timekeeper* = nullptr); Future<Unit> sleep(Duration, Timekeeper* = nullptr);
Future<Unit> sleepUnsafe(Duration, Timekeeper* = nullptr);
/** /**
* Set func as the callback for each input Future and return a vector of * Set func as the callback for each input Future and return a vector of
......
...@@ -79,6 +79,12 @@ TEST(Timekeeper, futureSleep) { ...@@ -79,6 +79,12 @@ TEST(Timekeeper, futureSleep) {
EXPECT_GE(now() - t1, one_ms); EXPECT_GE(now() - t1, one_ms);
} }
TEST(Timekeeper, futureSleepUnsafe) {
auto t1 = now();
futures::sleepUnsafe(one_ms).get();
EXPECT_GE(now() - t1, one_ms);
}
TEST(Timekeeper, futureSleepHandlesNullTimekeeperSingleton) { TEST(Timekeeper, futureSleepHandlesNullTimekeeperSingleton) {
Singleton<ThreadWheelTimekeeper>::make_mock([] { return nullptr; }); Singleton<ThreadWheelTimekeeper>::make_mock([] { return nullptr; });
SCOPE_EXIT { SCOPE_EXIT {
......
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