In SemiFuture members, fix DCHECK of pointer types
[folly.git] / folly / futures / Future.cpp
index 78f33d2608426dcb8b7ed31463d38852ef6f94ea..49e4c02c3ad358f04e6d10cbc320a66fca4c68cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 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 Future<void>;
+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 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();
   }
-  return tk->after(dur);
-}
-
-}}
-
-namespace folly { namespace detail {
 
-template <>
-CollectContext<void>::~CollectContext() {
-  if (!threw.exchange(true)) {
-    p.setValue();
+  if (UNLIKELY(!tk)) {
+    return makeFuture<Unit>(NoTimekeeper());
   }
-}
 
-template <>
-void CollectContext<void>::setPartialResult(size_t i, Try<void>& t) {
-  // Nothing to do for void
+  return tk->after(dur);
 }
 
-}}
+} // namespace futures
+} // namespace folly