Commit 679b1887 authored by Xavier Thompson's avatar Xavier Thompson

examples/: Adapt to new exception propagation

parent b7c7788b
......@@ -18,51 +18,46 @@ Task<void> hello(int id) {
co_return;
}
Task<void> fail() {
Task<void> fail(int delay) {
volatile int n = fibo(delay);
(void) n;
throw std::exception();
co_return;
}
Join<void> fail_join() {
co_await fork(fail());
Join<void> fail_join(int delay = 0) {
co_await fork(fail(delay));
}
Join<void> join_sync(int max) {
for (int id = 0; id < max; id++) {
co_await fork(hello(id));
}
try {
co_await fork(fail_join());
LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
} catch(std::exception &) {
LOG(" ... fork(fail_join()) did throw, rethrowing");
throw;
}
co_await fork(fail_join());
LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
LOG(" ... sync()");
try
{
co_await Sync();
LOG(" ... ERROR sync() did not throw");
} catch(std::exception &) {
LOG(" ... OK sync() did throw, rethrowing");
throw;
}
co_await Sync();
LOG(" ... ERROR sync() did not throw");
}
Join<void> join_no_sync(int max) {
for (int id = 0; id < max; id++) {
co_await fork(hello(id));
}
try {
co_await fork(fail_join());
LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
} catch(std::exception &) {
LOG(" ... fork(fail_join()) did throw, rethrowing");
throw;
}
co_await fork(fail_join());
LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
LOG(" ... join_no_sync(%d) is exiting normally", max);
}
Join<void> join_infinite_fork_loop() {
co_await fork(fail_join(25));
LOG(" ... fork(fail_join()) did not throw (stolen continuation)");
LOG(" ... now looping forever");
for (int id = 0; ; id++) {
co_await fork(hello(id));
}
}
Root root_sync(int max) {
try {
LOG(">>> join_sync(%d)", max);
......@@ -83,11 +78,21 @@ Root root_no_sync(int max) {
}
}
Root root_infinite_fork_loop() {
try {
LOG(">>> join_infinite_fork_loop()");
co_await join_infinite_fork_loop();
} catch(std::exception &) {
LOG("OK join_infinite_fork_loop() did throw eventually\n");
}
}
int main() {
root_sync(0).call();
root_sync(20).call();
root_no_sync(0).call();
root_no_sync(20).call();
root_infinite_fork_loop().call();
puts("done");
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment