summaryrefslogtreecommitdiffhomepage
path: root/misc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-27 09:57:33 +0100
committerTyge Løvset <[email protected]>2023-02-27 10:16:59 +0100
commitd37820ddc211aec2876950cd4f2236cc9b92c9eb (patch)
tree79a2fd040b214d2904860115cb8e6c888a973ff7 /misc
parent31459ecefc0d54399eafd9a18303868625f57a7c (diff)
downloadSTC-modified-d37820ddc211aec2876950cd4f2236cc9b92c9eb.tar.gz
STC-modified-d37820ddc211aec2876950cd4f2236cc9b92c9eb.zip
Let cco_end(value) return value. Should be last in function anyway.
Assume context always non-NULL when calling cco_alive(context).
Diffstat (limited to 'misc')
-rw-r--r--misc/examples/coread.c6
-rw-r--r--misc/examples/coroutines.c11
2 files changed, 5 insertions, 12 deletions
diff --git a/misc/examples/coread.c b/misc/examples/coread.c
index 3d49c5df..4df80339 100644
--- a/misc/examples/coread.c
+++ b/misc/examples/coread.c
@@ -24,8 +24,7 @@ bool file_nextline(struct file_nextline* U)
printf("finish\n");
cstr_drop(&U->line);
fclose(U->fp);
- cco_end();
- return false;
+ cco_end(false);
}
int main(void) {
@@ -33,9 +32,6 @@ int main(void) {
int n = 0;
while (file_nextline(&z)) {
printf("%3d %s\n", ++n, cstr_str(&z.line));
-
- // stop after 15 lines:
- if (n == 15) (void)cco_stop(&z);
}
printf("state %d\n", z.cco_state);
}
diff --git a/misc/examples/coroutines.c b/misc/examples/coroutines.c
index 5d2a178a..89b428ee 100644
--- a/misc/examples/coroutines.c
+++ b/misc/examples/coroutines.c
@@ -17,8 +17,7 @@ bool iterate(struct iterate* I) {
for (I->y = 0; I->y < I->max_y; I->y++)
cco_yield(true);
cco_final:
- cco_end();
- return false;
+ cco_end(false);
}
// Use coroutine to create a fibonacci sequence generator:
@@ -42,9 +41,7 @@ int64_t fibonacci(struct fibonacci* F) {
F->b = sum;
}
cco_final:
- cco_end();
-
- return -1;
+ cco_end(-1);
}
// Combine
@@ -60,10 +57,10 @@ bool combine(struct combine* C) {
cco_yield_coroutine(&C->it, iterate(&C->it), true);
cco_yield_coroutine(&C->fib, fibonacci(&C->fib), true);
// May reuse the C->it context; state has been reset to 0.
+ C->it.max_x = 2; C->it.max_y = 2;
cco_yield_coroutine(&C->it, iterate(&C->it), true);
cco_final: puts("final");
- cco_end();
- return false;
+ cco_end(false);
}
int main(void) {