基于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 967B

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