Add unit test for timeout=0
[folly.git] / folly / futures / Future.cpp
index fc7ff9b4002f8ef15d88adf25414967c617475d6..49e4c02c3ad358f04e6d10cbc320a66fca4c68cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include <folly/futures/Future.h>
-#include <folly/futures/detail/ThreadWheelTimekeeper.h>
 #include <folly/Likely.h>
+#include <folly/futures/ThreadWheelTimekeeper.h>
+
+namespace folly {
+
+// Instantiate the most common Future types to save compile time
+template class SemiFuture<Unit>;
+template class SemiFuture<bool>;
+template class SemiFuture<int>;
+template class SemiFuture<int64_t>;
+template class SemiFuture<std::string>;
+template class SemiFuture<double>;
+template class Future<Unit>;
+template class Future<bool>;
+template class Future<int>;
+template class Future<int64_t>;
+template class Future<std::string>;
+template class Future<double>;
+} // namespace folly
 
-namespace folly { namespace wangle { namespace futures {
+namespace folly {
+namespace futures {
 
-Future<void> sleep(Duration dur, Timekeeper* tk) {
+Future<Unit> sleep(Duration dur, Timekeeper* tk) {
+  std::shared_ptr<Timekeeper> tks;
   if (LIKELY(!tk)) {
-    tk = detail::getTimekeeperSingleton();
+    tks = folly::detail::getTimekeeperSingleton();
+    tk = tks.get();
   }
+
+  if (UNLIKELY(!tk)) {
+    return makeFuture<Unit>(NoTimekeeper());
+  }
+
   return tk->after(dur);
 }
 
-}}}
+} // namespace futures
+} // namespace folly