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.
 
 
 

57 lines
1.2 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. } }
  20. namespace asyncpp
  21. {
  22. /* future_trait for ant_then_impl */
  23. template<
  24. typename T_future,
  25. typename T_lambda>
  26. template<
  27. typename X_future>
  28. auto future_trait<__future::and_then_impl<T_future, T_lambda>, void>
  29. ::poll(X_future& self)
  30. {
  31. while (true)
  32. {
  33. if (self->second)
  34. {
  35. return self->second->poll();
  36. }
  37. else
  38. {
  39. auto r = self->first.poll();
  40. if (!r)
  41. return result_type::not_ready();
  42. self->second = std::make_unique<second_future_type>(as_future(r.call(self->lambda)));
  43. }
  44. }
  45. }
  46. }