|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
-
- #include <chrono>
- #include <iostream>
- #include <string>
- #include <conio.h>
- #include <thread>
-
- #include "librf.h"
-
- using namespace resumef;
-
- auto test_yield_int() -> generator_t<int>
- {
- std::cout << "1 will yield return" << std::endl;
- co_yield 1;
- std::cout << "2 will yield return" << std::endl;
- co_yield 2;
- std::cout << "3 will yield return" << std::endl;
- co_yield 3;
- std::cout << "4 will return" << std::endl;
- co_return 4;
-
- std::cout << "5 will never yield return" << std::endl;
- co_yield 5;
- }
-
- /*不能编译*/
- /*
- auto test_yield_void()
- {
- std::cout << "1 will yield return" << std::endl;
- co_yield ;
- std::cout << "2 will yield return" << std::endl;
- co_yield ;
- std::cout << "3 will yield return" << std::endl;
- co_yield ;
- std::cout << "4 will return" << std::endl;
- co_return ;
-
- std::cout << "5 will never yield return" << std::endl;
- co_yield ;
- }
- */
-
- auto test_yield_void() -> generator_t<>
- {
- std::cout << "block 1 will yield return" << std::endl;
- co_yield_void;
- std::cout << "block 2 will yield return" << std::endl;
- co_yield_void;
- std::cout << "block 3 will yield return" << std::endl;
- co_yield_void;
- std::cout << "block 4 will return" << std::endl;
- co_return_void;
-
- std::cout << "block 5 will never yield return" << std::endl;
- co_yield_void;
- }
-
- void resumable_main_yield_return()
- {
- go test_yield_int();
- this_scheduler()->run_until_notask();
-
- go test_yield_void();
- this_scheduler()->run_until_notask();
- }
|