mirror of
https://github.com/jrcutler/threadless.io.git
synced 2024-07-07 10:35:49 +00:00
Adding coroutine_defer() (with test)
This commit is contained in:
@@ -52,10 +52,23 @@ static void *fibonacci_generator(coroutine_t *coro, void *data)
|
||||
}
|
||||
|
||||
|
||||
static void deferred_puts(void *data)
|
||||
{
|
||||
puts(data);
|
||||
}
|
||||
|
||||
|
||||
static void *output_coroutine(coroutine_t *coro, void *data)
|
||||
{
|
||||
size_t *value = data;
|
||||
|
||||
if (coroutine_defer(coro, deferred_puts, "deferred output 0")) {
|
||||
return NULL;
|
||||
}
|
||||
if (coroutine_defer(coro, deferred_puts, "deferred output 1")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (NULL != value) {
|
||||
printf("%zu\n", *value);
|
||||
value = coroutine_yield(coro, value);
|
||||
|
Reference in New Issue
Block a user