|
- #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))
- { }
-
- } }
-
- namespace asyncpp
- {
-
- /* future_trait for ant_then_impl */
-
- template<
- typename T_future,
- typename T_lambda>
- template<
- typename X_future>
- auto future_trait<__future::and_then_impl<T_future, T_lambda>, void>
- ::poll(X_future& self)
- {
- while (true)
- {
- if (self->second)
- {
- return self->second->poll();
- }
- else
- {
- auto r = self->first.poll();
- if (!r)
- return result_type::not_ready();
-
- self->second = std::make_unique<second_future_type>(as_future(r.call(self->lambda)));
- }
- }
- }
-
- }
|