diff options
| author | Tyge Løvset <[email protected]> | 2023-05-01 23:11:45 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-05-01 23:11:45 +0200 |
| commit | 399eb8d0e1de2839d826a9e0cf123d90d00b0018 (patch) | |
| tree | a8731f86aa779af8412ba77e4d27fa5e66b94cab /misc/examples/coroutines.c | |
| parent | f916573e2b3652d9b3f6fb82aadd5f2cfb3ce2fe (diff) | |
| download | STC-modified-399eb8d0e1de2839d826a9e0cf123d90d00b0018.tar.gz STC-modified-399eb8d0e1de2839d826a9e0cf123d90d00b0018.zip | |
Replaced cco_yield(corocall, ctx, retval) with cco_await(cond) and cco_await_while(cond).
Diffstat (limited to 'misc/examples/coroutines.c')
| -rw-r--r-- | misc/examples/coroutines.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/misc/examples/coroutines.c b/misc/examples/coroutines.c index b11b8532..af9fef81 100644 --- a/misc/examples/coroutines.c +++ b/misc/examples/coroutines.c @@ -78,29 +78,27 @@ struct combined { int cco_state; }; + bool combined(struct combined* C) { cco_begin(C); - cco_yield(prime(&C->prm), &C->prm, true); - cco_yield(fibonacci(&C->fib), &C->fib, true); + cco_await(prime(&C->prm) == false); + cco_await(fibonacci(&C->fib) == false); // Reuse the C->prm context and extend the count: C->prm.count = 8; C->prm.result += 2; cco_reset(&C->prm); - cco_yield(prime(&C->prm), &C->prm, true); + cco_await(prime(&C->prm) == false); cco_final: puts("final comb"); cco_end(false); } -int main(void) { +int main(void) +{ struct combined comb = {.prm={.count=8}, .fib={14}}; - if (true) - while (combined(&comb)) - printf("Prime(%d)=%lld, Fib(%d)=%lld\n", - comb.prm.idx, (long long)comb.prm.result, - comb.fib.idx, (long long)comb.fib.result); - else - while (prime(&comb.prm)) - printf("Prime(%d)=%lld\n", - comb.prm.idx, (long long)comb.prm.result); + + while (combined(&comb)) + printf("Prime(%d)=%lld, Fib(%d)=%lld\n", + comb.prm.idx, (long long)comb.prm.result, + comb.fib.idx, (long long)comb.fib.result); } |
