|
- #pragma once
-
- #include "map.h"
-
- namespace asyncpp {
- namespace __future {
-
- /* and_then_impl */
-
- template<
- typename T_future,
- typename T_lambda>
- template<
- typename X_future,
- typename X_lambda>
- and_then_impl<T_future, T_lambda>
- ::and_then_impl(
- X_future&& p_first,
- X_lambda&& p_lambda)
- : first (std::forward<X_future>(p_first))
- , lambda(std::forward<X_lambda>(p_lambda))
- { }
-
- template<
- typename T_future,
- typename T_lambda>
- typename and_then_impl<T_future, T_lambda>::result_type
- and_then_impl<T_future, T_lambda>
- ::poll()
- {
- while (true)
- {
- if (second)
- {
- return second->poll();
- }
- else
- {
- auto r = first.poll();
- if (!r)
- return result_type::not_ready();
-
- second = std::make_unique<second_future_type>(r.call(lambda));
- }
- }
- }
-
- } }
|