#include "coro.hpp" #include #include #include Task task_test() { co_await Pass{}; for (unsigned i = 0; i < 3; ++i) co_yield i; co_return 1000; } int main() { const int task_count = 4; vector> tasks; for(int i = 0; i < task_count; i++) { auto t = task_test(); tasks.push_back(std::move(t)); } int done_count = 0; while(done_count < task_count) { for(int i = 0; i < task_count; i++) { Task &t = tasks[i]; if(t.done()) { // remove it from the tasks // this cause crash I think? t.destroy(); done_count++; } else { auto res = t(); if(t.state() == AWAIT) { cout << "AWAIT! " << t.state() << endl; } else if(t.state() != YIELD) { cout << "NOT YIELD: " << t.state() << endl; } else { cout << "T# " << i << " result " << res << " STATE " << t.state() << endl; } } } } }