simple.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2017-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. #pragma once
  17. #include <folly/futures/Future.h>
  18. #include <folly/futures/Promise.h>
  19. #include <cstdint>
  20. namespace folly {
  21. namespace python {
  22. namespace test {
  23. folly::Future<uint64_t> future_getValueX5(uint64_t val) {
  24. folly::Promise<uint64_t> p;
  25. auto f = p.getFuture();
  26. p.setWith([val] {
  27. if (val == 0) {
  28. throw std::invalid_argument("0 is not allowed");
  29. }
  30. return val * 5;
  31. });
  32. return f;
  33. }
  34. folly::Function<uint64_t()> getValueX5Fibers(uint64_t val) {
  35. return [val]() {
  36. if (val == 0) {
  37. throw std::invalid_argument("0 is not allowed");
  38. }
  39. return val * 5;
  40. };
  41. }
  42. } // namespace test
  43. } // namespace python
  44. } // namespace folly