std::shared_ptr<Timekeeper> tks;
if (LIKELY(!tk)) {
tks = folly::detail::getTimekeeperSingleton();
- tk = DCHECK_NOTNULL(tks.get());
+ tk = tks.get();
}
+
+ if (UNLIKELY(!tk)) {
+ return makeFuture<Unit>(NoTimekeeper());
+ }
+
return tk->after(dur);
}
[[noreturn]] void throwPredicateDoesNotObtain();
-struct FOLLY_EXPORT NoFutureInSplitter : FutureException {
+class FOLLY_EXPORT NoFutureInSplitter : FutureException {
+ public:
NoFutureInSplitter() : FutureException("No Future in this FutureSplitter") {}
};
[[noreturn]] void throwNoFutureInSplitter();
+
+class FOLLY_EXPORT NoTimekeeper : public FutureException {
+ public:
+ NoTimekeeper() : FutureException("No timekeeper available") {}
+};
}
*/
#include <folly/futures/Timekeeper.h>
+#include <folly/Singleton.h>
+#include <folly/futures/ThreadWheelTimekeeper.h>
#include <folly/portability/GTest.h>
using namespace folly;
EXPECT_GE(now() - t1, one_ms);
}
+TEST(Timekeeper, futureSleepHandlesNullTimekeeperSingleton) {
+ Singleton<ThreadWheelTimekeeper>::make_mock([] { return nullptr; });
+ SCOPE_EXIT {
+ Singleton<ThreadWheelTimekeeper>::make_mock();
+ };
+ EXPECT_THROW(futures::sleep(one_ms).get(), NoTimekeeper);
+}
+
TEST(Timekeeper, futureDelayed) {
auto t1 = now();
auto dur = makeFuture()