基于C++ Coroutines提案 ‘Stackless Resumable Functions’编写的协程库
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

test_async_routine.cpp 1.2KB

před 6 roky
před 6 roky
před 6 roky
před 6 roky
před 6 roky
před 6 roky
před 6 roky
před 6 roky
před 6 roky
123456789101112131415161718192021222324252627282930313233343536373839404142
  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. std::cout << "test_routine_use_timer" << std::endl;
  13. for (size_t i = 0; i < 3; ++i)
  14. {
  15. co_await resumef::sleep_for(100ms);
  16. std::cout << "timer after 100ms" << std::endl;
  17. std::cout << "1:frame=" << _coro_frame_ptr() << ",promise=" << _coro_promise_ptr(void) << std::endl << std::endl;
  18. }
  19. }
  20. future_vt test_routine_use_timer_2()
  21. {
  22. std::cout << "test_routine_use_timer_2" << std::endl;
  23. co_await test_routine_use_timer();
  24. std::cout << "2:frame=" << _coro_frame_ptr() << ",promise=" << _coro_promise_ptr(void) << std::endl << std::endl;
  25. co_await test_routine_use_timer();
  26. std::cout << "2:frame=" << _coro_frame_ptr() << ",promise=" << _coro_promise_ptr(void) << std::endl << std::endl;
  27. co_await test_routine_use_timer();
  28. std::cout << "2:frame=" << _coro_frame_ptr() << ",promise=" << _coro_promise_ptr(void) << std::endl << std::endl;
  29. }
  30. void resumable_main_routine()
  31. {
  32. go test_routine_use_timer_2();
  33. //go test_routine_use_timer();
  34. this_scheduler()->run_until_notask();
  35. }