基于C++ Coroutines提案 ‘Stackless Resumable Functions’编写的协程库
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.

test_async_routine.cpp 944B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <chrono>
  2. #include <iostream>
  3. #include <string>
  4. #include <thread>
  5. #include "librf.h"
  6. using namespace resumef;
  7. future_t<> test_routine_use_timer()
  8. {
  9. using namespace std::chrono;
  10. for (size_t i = 0; i < 3; ++i)
  11. {
  12. co_await resumef::sleep_for(100ms);
  13. std::cout << "timer after 100ms" << std::endl;
  14. std::cout << "1:frame=" << _coro_frame_ptr() << std::endl;
  15. }
  16. }
  17. future_t<> test_routine_use_timer_2()
  18. {
  19. std::cout << "test_routine_use_timer_2" << std::endl;
  20. co_await test_routine_use_timer();
  21. std::cout << "2:frame=" << _coro_frame_ptr() << std::endl;
  22. co_await test_routine_use_timer();
  23. std::cout << "2:frame=" << _coro_frame_ptr() << std::endl;
  24. co_await test_routine_use_timer();
  25. std::cout << "2:frame=" << _coro_frame_ptr() << std::endl;
  26. }
  27. void resumable_main_routine()
  28. {
  29. //go test_routine_use_timer_2();
  30. go test_routine_use_timer();
  31. this_scheduler()->run_until_notask();
  32. }