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