Restructing the source layout to make it nicer.
This commit is contained in:
parent
fff182b457
commit
cc3bb171e1
14 changed files with 166 additions and 33 deletions
52
scratchpad/corotest.cpp
Normal file
52
scratchpad/corotest.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "../coro.hpp"
|
||||
#include <coroutine>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using std::cout, std::endl;
|
||||
|
||||
Task<unsigned> 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;
|
||||
std::vector<Task<unsigned>> 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<unsigned> &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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue