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

1234567891011121314151617181920212223242526272829303132333435
  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_vt test_routine_use_timer()
  9. {
  10. using namespace std::chrono;
  11. for (size_t i = 0; i < 10; ++i)
  12. {
  13. co_await resumef::sleep_for(100ms);
  14. std::cout << "timer after 100ms." << std::endl;
  15. }
  16. }
  17. future_vt test_routine_use_timer_2()
  18. {
  19. co_await test_routine_use_timer();
  20. co_await test_routine_use_timer();
  21. co_await test_routine_use_timer();
  22. }
  23. void resumable_main_routine()
  24. {
  25. go test_routine_use_timer_2();
  26. //test_routine_use_timer();
  27. g_scheduler.run_until_notask();
  28. }