You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
1.0 KiB

  1. #pragma once
  2. #include "map.h"
  3. namespace asyncpp {
  4. namespace __future {
  5. /* and_then_impl */
  6. template<
  7. typename T_future,
  8. typename T_lambda>
  9. template<
  10. typename X_future,
  11. typename X_lambda>
  12. and_then_impl<T_future, T_lambda>
  13. ::and_then_impl(
  14. X_future&& p_first,
  15. X_lambda&& p_lambda)
  16. : first (std::forward<X_future>(p_first))
  17. , lambda(std::forward<X_lambda>(p_lambda))
  18. { }
  19. template<
  20. typename T_future,
  21. typename T_lambda>
  22. typename and_then_impl<T_future, T_lambda>::result_type
  23. and_then_impl<T_future, T_lambda>
  24. ::poll()
  25. {
  26. while (true)
  27. {
  28. if (second)
  29. {
  30. return second->poll();
  31. }
  32. else
  33. {
  34. auto r = first.poll();
  35. if (!r)
  36. return result_type::not_ready();
  37. second = std::make_unique<second_future_type>(r.call(lambda));
  38. }
  39. }
  40. }
  41. } }