From d37820ddc211aec2876950cd4f2236cc9b92c9eb Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 27 Feb 2023 09:57:33 +0100 Subject: Let cco_end(value) return value. Should be last in function anyway. Assume context always non-NULL when calling cco_alive(context). --- misc/examples/coread.c | 6 +----- misc/examples/coroutines.c | 11 ++++------- 2 files changed, 5 insertions(+), 12 deletions(-) (limited to 'misc') 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) { -- cgit v1.2.3