diff options
| author | Tyge Løvset <[email protected]> | 2023-06-13 18:21:04 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-06-13 18:21:04 +0200 |
| commit | 06f3ae1d904d776aea8a78113c16fc30309817ed (patch) | |
| tree | 9dd2332386a4cd4a76000d719bf999d41a05998c /include/stc/algo/coroutine.h | |
| parent | b564ef6bdfcd2437f1b4997f42054c45ccdedbb1 (diff) | |
| download | STC-modified-06f3ae1d904d776aea8a78113c16fc30309817ed.tar.gz STC-modified-06f3ae1d904d776aea8a78113c16fc30309817ed.zip | |
Added cco_closue(Ret, Closure) to define coroutine closure.
Added back cco_await_on(child) calls.
Diffstat (limited to 'include/stc/algo/coroutine.h')
| -rw-r--r-- | include/stc/algo/coroutine.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h index 5cd6d68f..61581f64 100644 --- a/include/stc/algo/coroutine.h +++ b/include/stc/algo/coroutine.h @@ -84,7 +84,21 @@ enum { case __LINE__: if (!(promise)) {return ret; goto _resume;} \ } while (0) -#define cco_run(co, call) while (call, !cco_done(co)) +#define cco_closure(Ret, Closure, ...) \ + struct Closure { \ + Ret (*coroutine)(struct Closure*); \ + __VA_ARGS__ \ + int cco_state; \ + } + +#define cco_resume(closure) (closure)->coroutine(closure) +#define cco_await_on(...) c_MACRO_OVERLOAD(cco_await_on, __VA_ARGS__) +#define cco_await_on_1(closure) cco_await_on_2(closure, cco_resume(closure)) +#define cco_await_on_2(co, func) cco_await_1((func(co), !cco_done(co))) + +#define cco_block_on(...) c_MACRO_OVERLOAD(cco_block_on, __VA_ARGS__) +#define cco_block_on_1(closure) while (cco_resume(closure), !cco_done(closure)) +#define cco_block_on_2(co, func) while (func(co), !cco_done(co)) #define cco_final \ *_state = cco_state_final; case cco_state_final |
