基于C++ Coroutines提案 ‘Stackless Resumable Functions’编写的协程库
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

test_async_routine.cpp 655B

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