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.
53 lines
1.0 KiB
53 lines
1.0 KiB
2 months ago
|
#include "../coro.hpp"
|
||
3 months ago
|
#include <coroutine>
|
||
|
#include <vector>
|
||
3 months ago
|
#include <iostream>
|
||
3 months ago
|
|
||
3 months ago
|
using std::cout, std::endl;
|
||
|
|
||
3 months ago
|
Task<unsigned> task_test()
|
||
|
{
|
||
3 months ago
|
co_await Pass{};
|
||
3 months ago
|
|
||
|
for (unsigned i = 0; i < 3; ++i)
|
||
|
co_yield i;
|
||
|
|
||
|
co_return 1000;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
const int task_count = 4;
|
||
3 months ago
|
std::vector<Task<unsigned>> tasks;
|
||
3 months ago
|
|
||
|
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<unsigned> &t = tasks[i];
|
||
|
|
||
|
if(t.done()) {
|
||
3 months ago
|
// remove it from the tasks
|
||
|
// this cause crash I think?
|
||
3 months ago
|
t.destroy();
|
||
|
done_count++;
|
||
|
} else {
|
||
|
auto res = t();
|
||
3 months ago
|
|
||
|
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;
|
||
|
}
|
||
3 months ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|