Future.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2014-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <folly/futures/Future.h>
  17. #include <folly/Likely.h>
  18. #include <folly/SingletonThreadLocal.h>
  19. #include <folly/futures/ThreadWheelTimekeeper.h>
  20. namespace folly {
  21. // Instantiate the most common Future types to save compile time
  22. template class SemiFuture<Unit>;
  23. template class SemiFuture<bool>;
  24. template class SemiFuture<int>;
  25. template class SemiFuture<int64_t>;
  26. template class SemiFuture<std::string>;
  27. template class SemiFuture<double>;
  28. template class Future<Unit>;
  29. template class Future<bool>;
  30. template class Future<int>;
  31. template class Future<int64_t>;
  32. template class Future<std::string>;
  33. template class Future<double>;
  34. } // namespace folly
  35. namespace folly {
  36. namespace futures {
  37. Future<Unit> sleep(Duration dur, Timekeeper* tk) {
  38. std::shared_ptr<Timekeeper> tks;
  39. if (LIKELY(!tk)) {
  40. tks = folly::detail::getTimekeeperSingleton();
  41. tk = tks.get();
  42. }
  43. if (UNLIKELY(!tk)) {
  44. return makeFuture<Unit>(FutureNoTimekeeper());
  45. }
  46. return tk->after(dur);
  47. }
  48. } // namespace futures
  49. } // namespace folly