25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

49 satır
948 B

  1. #include <gtest/gtest.h>
  2. #include <asyncpp.h>
  3. using namespace ::testing;
  4. using namespace ::asyncpp;
  5. struct delay
  6. {
  7. int const delay { 5 };
  8. int count { 0 };
  9. };
  10. namespace asyncpp
  11. {
  12. template<>
  13. struct future_trait<delay, void>
  14. : public future_base<future<delay, void>>
  15. {
  16. using value_type = int&;
  17. template<typename T_future>
  18. static inline auto poll(T_future& self)
  19. {
  20. using result_type = future_result<value_type>;
  21. if (self->count >= self->delay)
  22. return result_type::ready(self->count);
  23. ++self->count;
  24. return result_type::not_ready();
  25. }
  26. };
  27. }
  28. TEST(task_tests, poll)
  29. {
  30. auto t = make_task(as_future(delay { 5, 0 }));
  31. ASSERT_FALSE(t->poll());
  32. ASSERT_FALSE(t->poll());
  33. ASSERT_FALSE(t->poll());
  34. ASSERT_FALSE(t->poll());
  35. ASSERT_FALSE(t->poll());
  36. ASSERT_TRUE (t->poll());
  37. }