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

Add unsafe versions of TimeKeeper::after and TimeKeeper::at

Summary: In preparation for making TimeKeeper::at and TimeKeeper::after return SemiFutures to make more explicit the need to keep work off of the TimeKeeper's executor, add *Unsafe versions of both functions to migrate code to.

Differential Revision: D17052948

fbshipit-source-id: 4fb138862e417f02746ad4eaf71f091d37302e7a
parent 15a8ca73
......@@ -1926,6 +1926,13 @@ class Timekeeper {
/// will suffer.
virtual Future<Unit> after(Duration dur) = 0;
/// Unsafe version of after that returns an inline Future.
/// Any work added to this future will run inline on the Timekeeper's thread.
/// This can potentially cause problems with timing.
Future<Unit> afterUnsafe(Duration dur) {
return after(dur).semi().toUnsafeFuture();
}
/// Returns a future that will complete at the requested time.
///
/// You may cancel this Future to reclaim resources.
......@@ -1936,6 +1943,14 @@ class Timekeeper {
/// according to the steady clock.
template <class Clock>
Future<Unit> at(std::chrono::time_point<Clock> when);
/// Unsafe version of at that returns an inline Future.
/// Any work added to this future will run inline on the Timekeeper's thread.
/// This can potentially cause problems with timing.
template <class Clock>
Future<Unit> atUnsafe(std::chrono::time_point<Clock> when) {
return at(when).semi().toUnsafeFuture();
}
};
template <class T>
......
......@@ -48,6 +48,16 @@ TEST_F(TimekeeperFixture, after) {
EXPECT_GE(t2 - t1, awhile);
}
TEST_F(TimekeeperFixture, afterUnsafe) {
auto t1 = now();
auto f = timeLord_->afterUnsafe(awhile);
EXPECT_FALSE(f.isReady());
std::move(f).get();
auto t2 = now();
EXPECT_GE(t2 - t1, awhile);
}
TEST(Timekeeper, futureGet) {
Promise<int> p;
auto t = std::thread([&] { p.setValue(42); });
......
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