|
- #include <gtest/gtest.h>
-
- #include <asyncpp.h>
-
- using namespace ::testing;
- using namespace ::asyncpp;
-
- struct delay
- {
- int const delay { 5 };
- int count { 0 };
- };
-
- namespace asyncpp
- {
-
- template<>
- struct future_trait<delay, void>
- : public future_base<future<delay, void>>
- {
- using value_type = int&;
-
- template<typename T_future>
- static inline auto poll(T_future& self)
- {
- using result_type = future_result<value_type>;
-
- if (self->count >= self->delay)
- return result_type::ready(self->count);
-
- ++self->count;
- return result_type::not_ready();
- }
- };
-
- }
-
- TEST(task_tests, poll)
- {
- auto t = make_task(as_future(delay { 5, 0 }));
-
- ASSERT_FALSE(t->poll());
- ASSERT_FALSE(t->poll());
- ASSERT_FALSE(t->poll());
- ASSERT_FALSE(t->poll());
- ASSERT_FALSE(t->poll());
- ASSERT_TRUE (t->poll());
- }
|