summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/coroutines.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-05-03 16:45:37 +0200
committerTyge Løvset <[email protected]>2023-05-03 16:45:37 +0200
commit6b23e35287f26dad63abd755c5f365b443e025a3 (patch)
treec13c80d539efa1edbf7bc7d829f0e3d53e07e3b5 /misc/examples/coroutines.c
parente4efe2f9cc87e70e981ee75ec5c4d6db4cb60c49 (diff)
downloadSTC-modified-6b23e35287f26dad63abd755c5f365b443e025a3.tar.gz
STC-modified-6b23e35287f26dad63abd755c5f365b443e025a3.zip
Reverted from cco_await_with(promise, ret) to cco_await(promise, ret).
Diffstat (limited to 'misc/examples/coroutines.c')
-rw-r--r--misc/examples/coroutines.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/misc/examples/coroutines.c b/misc/examples/coroutines.c
index 00cedd84..a5db3291 100644
--- a/misc/examples/coroutines.c
+++ b/misc/examples/coroutines.c
@@ -36,7 +36,7 @@ bool prime(struct prime* g) {
}
}
cco_final:
- printf("final prm\n");
+ printf("final prm\n");
cco_end(true);
}
@@ -60,14 +60,15 @@ bool fibonacci(struct fibonacci* g) {
if (g->count-- == 0)
cco_return;
if (++g->idx > 1) {
- llong sum = g->result + g->b; // NB! locals lasts only until next cco_yield/cco_await!
+ // NB! locals lasts only until next cco_yield/cco_await!
+ llong sum = g->result + g->b;
g->result = g->b;
g->b = sum;
}
cco_yield(false);
}
cco_final:
- printf("final fib\n");
+ printf("final fib\n");
cco_end(true);
}
@@ -80,17 +81,18 @@ struct combined {
};
-bool combined(struct combined* C) {
- cco_begin(C);
- cco_await_with(prime(&C->prm), false);
- cco_await_with(fibonacci(&C->fib), false);
+bool combined(struct combined* g) {
+ cco_begin(g);
+ cco_await(prime(&g->prm), false);
+ cco_await(fibonacci(&g->fib), false);
- // Reuse the C->prm context and extend the count:
- C->prm.count = 8, C->prm.result += 2;
- cco_reset(&C->prm);
- cco_await_with(prime(&C->prm), false);
+ // Reuse the g->prm context and extend the count:
+ g->prm.count = 8, g->prm.result += 2;
+ cco_reset(&g->prm);
+ cco_await(prime(&g->prm), false);
- cco_final: puts("final comb");
+ cco_final:
+ puts("final combined");
cco_end(true);
}